aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llui/llkeywords.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-09-06 18:24:57 -0500
committerJacek Antonelli2008-09-06 18:25:07 -0500
commit798d367d54a6c6379ad355bd8345fa40e31e7fe9 (patch)
tree1921f1708cd0240648c97bc02df2c2ab5f2fc41e /linden/indra/llui/llkeywords.cpp
parentSecond Life viewer sources 1.20.15 (diff)
downloadmeta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.zip
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.gz
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.bz2
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.xz
Second Life viewer sources 1.21.0-RC
Diffstat (limited to 'linden/indra/llui/llkeywords.cpp')
-rw-r--r--linden/indra/llui/llkeywords.cpp63
1 files changed, 30 insertions, 33 deletions
diff --git a/linden/indra/llui/llkeywords.cpp b/linden/indra/llui/llkeywords.cpp
index d5d0d23..35f032a 100644
--- a/linden/indra/llui/llkeywords.cpp
+++ b/linden/indra/llui/llkeywords.cpp
@@ -69,7 +69,7 @@ LLKeywords::~LLKeywords()
69 std::for_each(mDelimiterTokenList.begin(), mDelimiterTokenList.end(), DeletePointer()); 69 std::for_each(mDelimiterTokenList.begin(), mDelimiterTokenList.end(), DeletePointer());
70} 70}
71 71
72BOOL LLKeywords::loadFromFile( const LLString& filename ) 72BOOL LLKeywords::loadFromFile( const std::string& filename )
73{ 73{
74 mLoaded = FALSE; 74 mLoaded = FALSE;
75 75
@@ -80,7 +80,7 @@ BOOL LLKeywords::loadFromFile( const LLString& filename )
80 char buffer[BUFFER_SIZE]; /* Flawfinder: ignore */ 80 char buffer[BUFFER_SIZE]; /* Flawfinder: ignore */
81 81
82 llifstream file; 82 llifstream file;
83 file.open(filename.c_str()); /* Flawfinder: ignore */ 83 file.open(filename); /* Flawfinder: ignore */
84 if( file.fail() ) 84 if( file.fail() )
85 { 85 {
86 llinfos << "LLKeywords::loadFromFile() Unable to open file: " << filename << llendl; 86 llinfos << "LLKeywords::loadFromFile() Unable to open file: " << filename << llendl;
@@ -106,52 +106,51 @@ BOOL LLKeywords::loadFromFile( const LLString& filename )
106 } 106 }
107 107
108 // start of line (SOL) 108 // start of line (SOL)
109 const char SOL_COMMENT[] = "#"; 109 std::string SOL_COMMENT("#");
110 const char SOL_WORD[] = "[word "; 110 std::string SOL_WORD("[word ");
111 const char SOL_LINE[] = "[line "; 111 std::string SOL_LINE("[line ");
112 const char SOL_ONE_SIDED_DELIMITER[] = "[one_sided_delimiter "; 112 std::string SOL_ONE_SIDED_DELIMITER("[one_sided_delimiter ");
113 const char SOL_TWO_SIDED_DELIMITER[] = "[two_sided_delimiter "; 113 std::string SOL_TWO_SIDED_DELIMITER("[two_sided_delimiter ");
114 114
115 LLColor3 cur_color( 1, 0, 0 ); 115 LLColor3 cur_color( 1, 0, 0 );
116 LLKeywordToken::TOKEN_TYPE cur_type = LLKeywordToken::WORD; 116 LLKeywordToken::TOKEN_TYPE cur_type = LLKeywordToken::WORD;
117 117
118 while (!file.eof()) 118 while (!file.eof())
119 { 119 {
120 buffer[0] = 0;
120 file.getline( buffer, BUFFER_SIZE ); 121 file.getline( buffer, BUFFER_SIZE );
121 if( !strncmp( buffer, SOL_COMMENT, strlen(SOL_COMMENT) ) ) /* Flawfinder: ignore */ 122 std::string line(buffer);
123 if( line.find(SOL_COMMENT) == 0 )
122 { 124 {
123 continue; 125 continue;
124 } 126 }
125 else 127 else if( line.find(SOL_WORD) == 0 )
126 if( !strncmp( buffer, SOL_WORD, strlen(SOL_WORD) ) ) /* Flawfinder: ignore */
127 { 128 {
128 cur_color = readColor( buffer + strlen(SOL_WORD) ); /* Flawfinder: ignore */ 129 cur_color = readColor( line.substr(SOL_WORD.size()) );
129 cur_type = LLKeywordToken::WORD; 130 cur_type = LLKeywordToken::WORD;
130 continue; 131 continue;
131 } 132 }
132 else 133 else if( line.find(SOL_LINE) == 0 )
133 if( !strncmp( buffer, SOL_LINE, strlen(SOL_LINE) ) ) /* Flawfinder: ignore */
134 { 134 {
135 cur_color = readColor( buffer + strlen(SOL_LINE) ); /* Flawfinder: ignore */ 135 cur_color = readColor( line.substr(SOL_LINE.size()) );
136 cur_type = LLKeywordToken::LINE; 136 cur_type = LLKeywordToken::LINE;
137 continue; 137 continue;
138 } 138 }
139 else 139 else if( line.find(SOL_TWO_SIDED_DELIMITER) == 0 )
140 if( !strncmp( buffer, SOL_TWO_SIDED_DELIMITER, strlen(SOL_TWO_SIDED_DELIMITER) ) ) /* Flawfinder: ignore */
141 { 140 {
142 cur_color = readColor( buffer + strlen(SOL_TWO_SIDED_DELIMITER) ); /* Flawfinder: ignore */ 141 cur_color = readColor( line.substr(SOL_TWO_SIDED_DELIMITER.size()) );
143 cur_type = LLKeywordToken::TWO_SIDED_DELIMITER; 142 cur_type = LLKeywordToken::TWO_SIDED_DELIMITER;
144 continue; 143 continue;
145 } 144 }
146 if( !strncmp( buffer, SOL_ONE_SIDED_DELIMITER, strlen(SOL_ONE_SIDED_DELIMITER) ) ) /* Flawfinder: ignore */ 145 else if( line.find(SOL_ONE_SIDED_DELIMITER) == 0 )
147 { 146 {
148 cur_color = readColor( buffer + strlen(SOL_ONE_SIDED_DELIMITER) ); /* Flawfinder: ignore */ 147 cur_color = readColor( line.substr(SOL_ONE_SIDED_DELIMITER.size()) );
149 cur_type = LLKeywordToken::ONE_SIDED_DELIMITER; 148 cur_type = LLKeywordToken::ONE_SIDED_DELIMITER;
150 continue; 149 continue;
151 } 150 }
152 151
153 LLString token_buffer( buffer ); 152 std::string token_buffer( line );
154 LLString::trim(token_buffer); 153 LLStringUtil::trim(token_buffer);
155 154
156 typedef boost::tokenizer<boost::char_separator<char> > tokenizer; 155 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
157 boost::char_separator<char> sep_word("", " \t"); 156 boost::char_separator<char> sep_word("", " \t");
@@ -161,26 +160,26 @@ BOOL LLKeywords::loadFromFile( const LLString& filename )
161 if( !token_buffer.empty() && token_word_iter != word_tokens.end() ) 160 if( !token_buffer.empty() && token_word_iter != word_tokens.end() )
162 { 161 {
163 // first word is keyword 162 // first word is keyword
164 LLString keyword = (*token_word_iter); 163 std::string keyword = (*token_word_iter);
165 LLString::trim(keyword); 164 LLStringUtil::trim(keyword);
166 165
167 // following words are tooltip 166 // following words are tooltip
168 LLString tool_tip; 167 std::string tool_tip;
169 while (++token_word_iter != word_tokens.end()) 168 while (++token_word_iter != word_tokens.end())
170 { 169 {
171 tool_tip += (*token_word_iter); 170 tool_tip += (*token_word_iter);
172 } 171 }
173 LLString::trim(tool_tip); 172 LLStringUtil::trim(tool_tip);
174 173
175 if( !tool_tip.empty() ) 174 if( !tool_tip.empty() )
176 { 175 {
177 // Replace : with \n for multi-line tool tips. 176 // Replace : with \n for multi-line tool tips.
178 LLString::replaceChar( tool_tip, ':', '\n' ); 177 LLStringUtil::replaceChar( tool_tip, ':', '\n' );
179 addToken(cur_type, keyword, cur_color, tool_tip ); 178 addToken(cur_type, keyword, cur_color, tool_tip );
180 } 179 }
181 else 180 else
182 { 181 {
183 addToken(cur_type, keyword, cur_color, NULL ); 182 addToken(cur_type, keyword, cur_color, LLStringUtil::null );
184 } 183 }
185 } 184 }
186 } 185 }
@@ -193,9 +192,9 @@ BOOL LLKeywords::loadFromFile( const LLString& filename )
193 192
194// Add the token as described 193// Add the token as described
195void LLKeywords::addToken(LLKeywordToken::TOKEN_TYPE type, 194void LLKeywords::addToken(LLKeywordToken::TOKEN_TYPE type,
196 const LLString& key_in, 195 const std::string& key_in,
197 const LLColor3& color, 196 const LLColor3& color,
198 const LLString& tool_tip_in ) 197 const std::string& tool_tip_in )
199{ 198{
200 LLWString key = utf8str_to_wstring(key_in); 199 LLWString key = utf8str_to_wstring(key_in);
201 LLWString tool_tip = utf8str_to_wstring(tool_tip_in); 200 LLWString tool_tip = utf8str_to_wstring(tool_tip_in);
@@ -219,7 +218,7 @@ void LLKeywords::addToken(LLKeywordToken::TOKEN_TYPE type,
219 } 218 }
220} 219}
221 220
222LLColor3 LLKeywords::readColor( const LLString& s ) 221LLColor3 LLKeywords::readColor( const std::string& s )
223{ 222{
224 F32 r, g, b; 223 F32 r, g, b;
225 r = g = b = 0.0f; 224 r = g = b = 0.0f;
@@ -296,7 +295,6 @@ void LLKeywords::findSegments(std::vector<LLTextSegment *>* seg_list, const LLWS
296 } 295 }
297 S32 seg_end = cur - base; 296 S32 seg_end = cur - base;
298 297
299 //llinfos << "Seg: [" << (char*)LLString( base, seg_start, seg_end-seg_start) << "]" << llendl;
300 LLTextSegment* text_segment = new LLTextSegment( cur_token->getColor(), seg_start, seg_end ); 298 LLTextSegment* text_segment = new LLTextSegment( cur_token->getColor(), seg_start, seg_end );
301 text_segment->setToken( cur_token ); 299 text_segment->setToken( cur_token );
302 insertSegment( seg_list, text_segment, text_len, defaultColor); 300 insertSegment( seg_list, text_segment, text_len, defaultColor);
@@ -406,7 +404,6 @@ void LLKeywords::findSegments(std::vector<LLTextSegment *>* seg_list, const LLWS
406 } 404 }
407 405
408 406
409 //llinfos << "Seg: [" << (char*)LLString( base, seg_start, seg_end-seg_start ) << "]" << llendl;
410 LLTextSegment* text_segment = new LLTextSegment( cur_delimiter->getColor(), seg_start, seg_end ); 407 LLTextSegment* text_segment = new LLTextSegment( cur_delimiter->getColor(), seg_start, seg_end );
411 text_segment->setToken( cur_delimiter ); 408 text_segment->setToken( cur_delimiter );
412 insertSegment( seg_list, text_segment, text_len, defaultColor); 409 insertSegment( seg_list, text_segment, text_len, defaultColor);
@@ -518,7 +515,7 @@ void LLKeywordToken::dump()
518 mColor.mV[VX] << ", " << 515 mColor.mV[VX] << ", " <<
519 mColor.mV[VY] << ", " << 516 mColor.mV[VY] << ", " <<
520 mColor.mV[VZ] << "] [" << 517 mColor.mV[VZ] << "] [" <<
521 mToken.c_str() << "]" << 518 wstring_to_utf8str(mToken) << "]" <<
522 llendl; 519 llendl;
523} 520}
524 521