Go to the source code of this file.
Functions | |
FENNEL_BEGIN_CPPFILE ("$Id: //open/dev/fennel/common/ResourceBundle.cpp#14 $") | |
static string | globalResourceLocation ("") |
static string | MISSING_KEY ("[[unknown key]]") |
static string | convertPropertyToBoost (string &message) |
FENNEL_END_CPPFILE ("$Id: //open/dev/fennel/common/ResourceBundle.cpp#14 $") | |
Variables | |
static const char | APOS = '\'' |
static const char | LEFT_BRACE = '{' |
static const char | RIGHT_BRACE = '}' |
static const char | COMMA = ',' |
static string convertPropertyToBoost | ( | string & | message | ) | [static] |
Definition at line 139 of file ResourceBundle.cpp.
References APOS, COMMA, LEFT_BRACE, min(), and RIGHT_BRACE.
Referenced by ResourceBundle::loadMessages().
00140 { 00141 stringstream ss; 00142 00143 bool quoted = false; 00144 char ch; 00145 char nextCh; 00146 00147 for (int i = 0, n = message.length(); i < n; i++) { 00148 ch = message[i]; 00149 nextCh = (i + 1 < n) ? message[i + 1] : 0; 00150 00151 if (ch == APOS) { 00152 if (nextCh != APOS) { 00153 // Bare apostrophes signal start/end of QuotedString in the BNF 00154 quoted = !quoted; 00155 continue; 00156 } 00157 00158 // Quoted or not, the next character is an apostrophe, so we 00159 // output an apostrophe. 00160 ss << APOS; 00161 i++; // skip nextCh 00162 continue; 00163 } 00164 00165 if (quoted || ch != LEFT_BRACE) { 00166 ss << ch; 00167 continue; 00168 } 00169 00170 // Handle an argument 00171 string::size_type commaPos = message.find(COMMA, i); 00172 string::size_type bracketPos = message.find(RIGHT_BRACE, i); 00173 if (bracketPos == string::npos) { 00174 // Bad format -- give up 00175 return message; 00176 } 00177 00178 int argEndIndex = (commaPos == string::npos 00179 ? bracketPos 00180 : min(commaPos, bracketPos)); 00181 00182 int argIndex = boost::lexical_cast<int>( 00183 message.substr(i + 1, argEndIndex - (i + 1))); 00184 00185 // Boost args are 1-based 00186 ss << '%' << (argIndex + 1) << '%'; 00187 00188 // Find the end of the argument tag 00189 bool quotedPattern = false; 00190 int bracketDepth = 0; 00191 i = argEndIndex; 00192 00193 bool done = false; 00194 while (!done && i < n) { 00195 ch = message[i]; 00196 00197 switch (ch) { 00198 default: 00199 i++; 00200 break; 00201 00202 case APOS: 00203 quotedPattern = !quotedPattern; 00204 i++; 00205 break; 00206 00207 case LEFT_BRACE: 00208 if (!quotedPattern) { 00209 bracketDepth++; 00210 } 00211 i++; 00212 break; 00213 00214 case RIGHT_BRACE: 00215 if (!quotedPattern) { 00216 if (bracketDepth > 0) { 00217 bracketDepth--; 00218 } else { 00219 // end of pattern! 00220 done = true; 00221 break; 00222 } 00223 } 00224 i++; 00225 break; 00226 } 00227 } 00228 00229 if (i == n) { 00230 // couldn't find end of pattern -- give up 00231 return message; 00232 } 00233 } 00234 00235 return ss.str(); 00236 }
FENNEL_BEGIN_CPPFILE | ( | "$Id: //open/dev/fennel/common/ResourceBundle.cpp#14 $" | ) |
FENNEL_END_CPPFILE | ( | "$Id: //open/dev/fennel/common/ResourceBundle.cpp#14 $" | ) |
static string globalResourceLocation | ( | "" | ) | [static] |
Referenced by ResourceBundle::loadMessages(), and ResourceBundle::setGlobalResourceFileLocation().
static string MISSING_KEY | ( | "]" | [[unknown key] | ) | [static] |
Referenced by ResourceBundle::getMessage().
const char APOS = '\'' [static] |
const char COMMA = ',' [static] |
Definition at line 137 of file ResourceBundle.cpp.
const char LEFT_BRACE = '{' [static] |
const char RIGHT_BRACE = '}' [static] |