| 182 | } |
| 183 | |
| 184 | status_t parseStyledString(Bundle* bundle, |
| 185 | const char* fileName, |
| 186 | ResXMLTree* inXml, |
| 187 | const String16& endTag, |
| 188 | String16* outString, |
| 189 | Vector<StringPool::entry_style_span>* outSpans, |
| 190 | bool isFormatted, |
| 191 | bool pseudolocalize) |
| 192 | { |
| 193 | Vector<StringPool::entry_style_span> spanStack; |
| 194 | String16 curString; |
| 195 | String16 rawString; |
| 196 | const char* errorMsg; |
| 197 | int xliffDepth = 0; |
| 198 | bool firstTime = true; |
| 199 | |
| 200 | size_t len; |
| 201 | ResXMLTree::event_code_t code; |
| 202 | while ((code=inXml->next()) != ResXMLTree::END_DOCUMENT && code != ResXMLTree::BAD_DOCUMENT) { |
| 203 | |
| 204 | if (code == ResXMLTree::TEXT) { |
| 205 | String16 text(inXml->getText(&len)); |
| 206 | if (firstTime && text.size() > 0) { |
| 207 | firstTime = false; |
| 208 | if (text.string()[0] == '@') { |
| 209 | // If this is a resource reference, don't do the pseudoloc. |
| 210 | pseudolocalize = false; |
| 211 | } |
| 212 | } |
| 213 | if (xliffDepth == 0 && pseudolocalize) { |
| 214 | std::string orig(String8(text).string()); |
| 215 | std::string pseudo = pseudolocalize_string(orig); |
| 216 | curString.append(String16(String8(pseudo.c_str()))); |
| 217 | } else { |
| 218 | if (isFormatted && hasSubstitutionErrors(fileName, inXml, text) != NO_ERROR) { |
| 219 | return UNKNOWN_ERROR; |
| 220 | } else { |
| 221 | curString.append(text); |
| 222 | } |
| 223 | } |
| 224 | } else if (code == ResXMLTree::START_TAG) { |
| 225 | const String16 element16(inXml->getElementName(&len)); |
| 226 | const String8 element8(element16); |
| 227 | |
| 228 | size_t nslen; |
| 229 | const uint16_t* ns = inXml->getElementNamespace(&nslen); |
| 230 | if (ns == NULL) { |
| 231 | ns = (const uint16_t*)"\0\0"; |
| 232 | nslen = 0; |
| 233 | } |
| 234 | const String8 nspace(String16(ns, nslen)); |
| 235 | if (nspace == XLIFF_XMLNS) { |
| 236 | const int N = sizeof(ALLOWED_XLIFF_ELEMENTS)/sizeof(ALLOWED_XLIFF_ELEMENTS[0]); |
| 237 | for (int i=0; i<N; i++) { |
| 238 | if (element8 == ALLOWED_XLIFF_ELEMENTS[i]) { |
| 239 | xliffDepth++; |
| 240 | // in this case, treat it like it was just text, in other words, do nothing |
| 241 | // here and silently drop this element |
no test coverage detected