static int parseDwarfDie(char *line, Dwarf_Die *lastCreatedDie, Dwarf_Die *currentDie, size_t *lastIndent, size_t spaces, Dwarf_Error *error) { int ret = DW_DLV_OK; Dwarf_Half tag = DW_TAG_unknown; size_t span = strcspn(line, " "); parseTagString(line, span, &tag); if (DW_TAG_unknown == tag) { *currentDie = NULL; } else { Dwarf_Die newDie = new Dwarf_Die_s; if (NULL == newDie) { ret = DW_DLV_ERROR; setError(error, DW_DLE_MAF); } else { newDie->_tag = tag; newDie->_attribute = NULL; newDie->_context = Dwarf_CU_Context::_currentCU; newDie->_child = NULL; newDie->_sibling = NULL; if (0 == *lastIndent) { /* No last indent indicates that this Die is at the start of a CU. */ newDie->_parent = NULL; Dwarf_CU_Context::_currentCU->_die = newDie; } else if (spaces > *lastIndent) { /* If the Die is indended farther than the last Die, it is * a first child. */ newDie->_parent = *lastCreatedDie; (*lastCreatedDie)->_child = newDie; } else if (spaces <= *lastIndent) { /* If the Die is indented equally to the last Die, it is a * sibling Die. If the indentation has decreased, the last * Die would have been updated to one level up the tree when * a "NULL" line indicated there were no more siblings. */ newDie->_parent = (*lastCreatedDie)->_parent; (*lastCreatedDie)->_sibling = newDie; } *lastCreatedDie = newDie; *currentDie = newDie; *lastIndent = spaces; } } return ret; }
static int32_t _uloc_minimizeSubtags(const char* localeID, char* minimizedLocaleID, int32_t minimizedLocaleIDCapacity, UErrorCode* err) { /** * ULOC_FULLNAME_CAPACITY will provide enough capacity * that we can build a string that contains the language, * script and region code without worrying about overrunning * the user-supplied buffer. **/ char maximizedTagBuffer[ULOC_FULLNAME_CAPACITY]; int32_t maximizedTagBufferLength = sizeof(maximizedTagBuffer); char lang[ULOC_LANG_CAPACITY]; int32_t langLength = sizeof(lang); char script[ULOC_SCRIPT_CAPACITY]; int32_t scriptLength = sizeof(script); char region[ULOC_COUNTRY_CAPACITY]; int32_t regionLength = sizeof(region); const char* trailing = ""; int32_t trailingLength = 0; int32_t trailingIndex = 0; if(U_FAILURE(*err)) { goto error; } else if (localeID == NULL || minimizedLocaleID == NULL || minimizedLocaleIDCapacity <= 0) { goto error; } trailingIndex = parseTagString( localeID, lang, &langLength, script, &scriptLength, region, ®ionLength, err); if(U_FAILURE(*err)) { /* Overflow indicates an illegal argument error */ if (*err == U_BUFFER_OVERFLOW_ERROR) { *err = U_ILLEGAL_ARGUMENT_ERROR; } goto error; } /* Find the spot where the variants or the keywords begin, if any. */ while (_isIDSeparator(localeID[trailingIndex])) { trailingIndex++; } trailing = &localeID[trailingIndex]; trailingLength = (int32_t)uprv_strlen(trailing); CHECK_TRAILING_VARIANT_SIZE(trailing, trailingLength); createTagString( lang, langLength, script, scriptLength, region, regionLength, NULL, 0, maximizedTagBuffer, maximizedTagBufferLength, err); if(U_FAILURE(*err)) { goto error; } /** * First, we need to first get the maximization * from AddLikelySubtags. **/ maximizedTagBufferLength = uloc_addLikelySubtags( maximizedTagBuffer, maximizedTagBuffer, maximizedTagBufferLength, err); if(U_FAILURE(*err)) { goto error; } /** * Start first with just the language. **/ { char tagBuffer[ULOC_FULLNAME_CAPACITY]; const int32_t tagBufferLength = createLikelySubtagsString( lang, langLength, NULL, 0, NULL, 0, NULL, 0, tagBuffer, sizeof(tagBuffer), err); if(U_FAILURE(*err)) { goto error; } else if (uprv_strnicmp( maximizedTagBuffer, tagBuffer, tagBufferLength) == 0) { return createTagString( lang, langLength, NULL, 0, NULL, 0, trailing, trailingLength, minimizedLocaleID, minimizedLocaleIDCapacity, err); } } /** * Next, try the language and region. **/ if (regionLength > 0) { char tagBuffer[ULOC_FULLNAME_CAPACITY]; const int32_t tagBufferLength = createLikelySubtagsString( lang, langLength, NULL, 0, region, regionLength, NULL, 0, tagBuffer, sizeof(tagBuffer), err); if(U_FAILURE(*err)) { goto error; } else if (uprv_strnicmp( maximizedTagBuffer, tagBuffer, tagBufferLength) == 0) { return createTagString( lang, langLength, NULL, 0, region, regionLength, trailing, trailingLength, minimizedLocaleID, minimizedLocaleIDCapacity, err); } } /** * Finally, try the language and script. This is our last chance, * since trying with all three subtags would only yield the * maximal version that we already have. **/ if (scriptLength > 0 && regionLength > 0) { char tagBuffer[ULOC_FULLNAME_CAPACITY]; const int32_t tagBufferLength = createLikelySubtagsString( lang, langLength, script, scriptLength, NULL, 0, NULL, 0, tagBuffer, sizeof(tagBuffer), err); if(U_FAILURE(*err)) { goto error; } else if (uprv_strnicmp( maximizedTagBuffer, tagBuffer, tagBufferLength) == 0) { return createTagString( lang, langLength, script, scriptLength, NULL, 0, trailing, trailingLength, minimizedLocaleID, minimizedLocaleIDCapacity, err); } } { /** * If we got here, return the locale ID parameter. **/ const int32_t localeIDLength = (int32_t)uprv_strlen(localeID); uprv_memcpy( minimizedLocaleID, localeID, localeIDLength <= minimizedLocaleIDCapacity ? localeIDLength : minimizedLocaleIDCapacity); return u_terminateChars( minimizedLocaleID, minimizedLocaleIDCapacity, localeIDLength, err); } error: if (!U_FAILURE(*err)) { *err = U_ILLEGAL_ARGUMENT_ERROR; } return -1; }
static int32_t _uloc_addLikelySubtags(const char* localeID, char* maximizedLocaleID, int32_t maximizedLocaleIDCapacity, UErrorCode* err) { char lang[ULOC_LANG_CAPACITY]; int32_t langLength = sizeof(lang); char script[ULOC_SCRIPT_CAPACITY]; int32_t scriptLength = sizeof(script); char region[ULOC_COUNTRY_CAPACITY]; int32_t regionLength = sizeof(region); const char* trailing = ""; int32_t trailingLength = 0; int32_t trailingIndex = 0; int32_t resultLength = 0; if(U_FAILURE(*err)) { goto error; } else if (localeID == NULL || maximizedLocaleID == NULL || maximizedLocaleIDCapacity <= 0) { goto error; } trailingIndex = parseTagString( localeID, lang, &langLength, script, &scriptLength, region, ®ionLength, err); if(U_FAILURE(*err)) { /* Overflow indicates an illegal argument error */ if (*err == U_BUFFER_OVERFLOW_ERROR) { *err = U_ILLEGAL_ARGUMENT_ERROR; } goto error; } /* Find the length of the trailing portion. */ while (_isIDSeparator(localeID[trailingIndex])) { trailingIndex++; } trailing = &localeID[trailingIndex]; trailingLength = (int32_t)uprv_strlen(trailing); CHECK_TRAILING_VARIANT_SIZE(trailing, trailingLength); resultLength = createLikelySubtagsString( lang, langLength, script, scriptLength, region, regionLength, trailing, trailingLength, maximizedLocaleID, maximizedLocaleIDCapacity, err); if (resultLength == 0) { const int32_t localIDLength = (int32_t)uprv_strlen(localeID); /* * If we get here, we need to return localeID. */ uprv_memcpy( maximizedLocaleID, localeID, localIDLength <= maximizedLocaleIDCapacity ? localIDLength : maximizedLocaleIDCapacity); resultLength = u_terminateChars( maximizedLocaleID, maximizedLocaleIDCapacity, localIDLength, err); } return resultLength; error: if (!U_FAILURE(*err)) { *err = U_ILLEGAL_ARGUMENT_ERROR; } return -1; }