* xmlCheckLanguageID: * @lang: pointer to the string value * * DEPRECATED: Internal function, do not use. * * Checks that the value conforms to the LanguageID production: * * NOTE: this is somewhat deprecated, those productions were removed from * the XML Second edition. * * [33] LanguageID ::= Langcode ('-' Subcode)* * [34] Langcode ::= ISO639Code | IanaCode | UserCode * [35]
| 1298 | * Returns 1 if correct 0 otherwise |
| 1299 | **/ |
| 1300 | int |
| 1301 | xmlCheckLanguageID(const xmlChar * lang) |
| 1302 | { |
| 1303 | const xmlChar *cur = lang, *nxt; |
| 1304 | |
| 1305 | if (cur == NULL) |
| 1306 | return (0); |
| 1307 | if (((cur[0] == 'i') && (cur[1] == '-')) || |
| 1308 | ((cur[0] == 'I') && (cur[1] == '-')) || |
| 1309 | ((cur[0] == 'x') && (cur[1] == '-')) || |
| 1310 | ((cur[0] == 'X') && (cur[1] == '-'))) { |
| 1311 | /* |
| 1312 | * Still allow IANA code and user code which were coming |
| 1313 | * from the previous version of the XML-1.0 specification |
| 1314 | * it's deprecated but we should not fail |
| 1315 | */ |
| 1316 | cur += 2; |
| 1317 | while (((cur[0] >= 'A') && (cur[0] <= 'Z')) || |
| 1318 | ((cur[0] >= 'a') && (cur[0] <= 'z'))) |
| 1319 | cur++; |
| 1320 | return(cur[0] == 0); |
| 1321 | } |
| 1322 | nxt = cur; |
| 1323 | while (((nxt[0] >= 'A') && (nxt[0] <= 'Z')) || |
| 1324 | ((nxt[0] >= 'a') && (nxt[0] <= 'z'))) |
| 1325 | nxt++; |
| 1326 | if (nxt - cur >= 4) { |
| 1327 | /* |
| 1328 | * Reserved |
| 1329 | */ |
| 1330 | if ((nxt - cur > 8) || (nxt[0] != 0)) |
| 1331 | return(0); |
| 1332 | return(1); |
| 1333 | } |
| 1334 | if (nxt - cur < 2) |
| 1335 | return(0); |
| 1336 | /* we got an ISO 639 code */ |
| 1337 | if (nxt[0] == 0) |
| 1338 | return(1); |
| 1339 | if (nxt[0] != '-') |
| 1340 | return(0); |
| 1341 | |
| 1342 | nxt++; |
| 1343 | cur = nxt; |
| 1344 | /* now we can have extlang or script or region or variant */ |
| 1345 | if ((nxt[0] >= '0') && (nxt[0] <= '9')) |
| 1346 | goto region_m49; |
| 1347 | |
| 1348 | while (((nxt[0] >= 'A') && (nxt[0] <= 'Z')) || |
| 1349 | ((nxt[0] >= 'a') && (nxt[0] <= 'z'))) |
| 1350 | nxt++; |
| 1351 | if (nxt - cur == 4) |
| 1352 | goto script; |
| 1353 | if (nxt - cur == 2) |
| 1354 | goto region; |
| 1355 | if ((nxt - cur >= 5) && (nxt - cur <= 8)) |
| 1356 | goto variant; |
| 1357 | if (nxt - cur != 3) |
no outgoing calls
no test coverage detected