-static char* parseFilename(const char* fileName, char* lang) {
- char* pos;
- char* pos2;
- int32_t first;
- int32_t second;
- char* str0 = NULL;
- char* str1 = NULL;
- char* str2 = NULL;
- char* str3 = NULL;
- int32_t index = 0;
- UBool ISO_tag = TRUE;
-
- ISOLanguages = uloc_getISOLanguages();
- ISOCountries = uloc_getISOCountries();
-
- pos = uprv_strrchr(fileName, U_FILE_SEP_CHAR);
- pos2 = uprv_strrchr(fileName, '.');
-
- if(pos == NULL) {
- first = -1;
- }else {
- first = (int32_t)(pos - fileName);
- }
- if(pos2 == NULL) {
- second = (int32_t)uprv_strlen(fileName);
- } else {
- second = (int32_t)(pos2 - fileName);
- }
- index = (int32_t)(second - first - 1);
- str0 = uprv_malloc(sizeof(char) * index + 1);
- uprv_memset(str0, 0, sizeof(char) * index + 1);
- uprv_strncpy(str0, fileName + first + 1, index);
-
- pos = uprv_strchr( str0, '_' );
- first = (int32_t)(pos - str0);
- if (pos == NULL) {
- str1 = uprv_malloc(sizeof(char)*uprv_strlen(str0)+1);
- uprv_memset(str1, 0, sizeof(char)*uprv_strlen(str0)+1);
- uprv_strcpy(str1, str0);
- } else {
- str1 = uprv_malloc(sizeof(char)*first+1);
- uprv_memset(str1, 0, sizeof(char)*first+1);
- uprv_strncpy(str1, str0, first);
- pos = uprv_strrchr( str0, '_' );
- second = (int32_t)(pos - str0);
- if(first != second && second-first != 1) {
- index = second - first-1;
- str2 = uprv_malloc(sizeof(char)*index+1);
- uprv_memset(str2, 0, sizeof(char)*index+1);
- uprv_strncpy(str2, str0 + first + 1, index );
- index = (int32_t)(uprv_strlen(str0) - second -1);
- str3 = uprv_malloc(sizeof(char)*index+1);
- uprv_memset(str3, 0, sizeof(char)*index+1);
- uprv_strncpy(str3, str0 + second + 1, index);
- } else if(first == second) {
- index = first;
- str1 = uprv_malloc(sizeof(char)*first+1);
- uprv_memset(str1, 0, sizeof(char)*first+1);
- uprv_strncpy(str1, str0, index );
- index = (int32_t)(uprv_strlen(str0) - second -1);
- str2 = uprv_malloc(sizeof(char)*index+1);
- uprv_memset(str2, 0, sizeof(char)*index+1);
- uprv_strncpy(str2, str0 + second + 1, index );
- }
- }
-
- if (str2 == NULL && str3 == NULL) {
- ISO_tag = checkISOLanguage(str1);
- if(ISO_tag) {
- lang = uprv_malloc(sizeof(char)*uprv_strlen(str1)+1);
- uprv_memset(lang, 0, sizeof(char)*uprv_strlen(str1)+1);
- uprv_strcpy(lang, str1);
- }
- } else if(str3 == NULL){
- ISO_tag = checkISOLanguage(str1);
- if (ISO_tag) {
- ISO_tag = checkISOCountry(str2);
- if (ISO_tag) {
- lang = uprv_malloc(sizeof(char)*uprv_strlen(str1)+1);
- uprv_memset(lang, 0, sizeof(char)*uprv_strlen(str1)+1);
- uprv_strcpy(lang, str1);
- }
- } else {
- ISO_tag = checkISOLanguage(str2);
- if (ISO_tag) {
- lang = uprv_malloc(sizeof(char)*uprv_strlen(str2)+1);
- uprv_memset(lang, 0, sizeof(char)*uprv_strlen(str2)+1);
- uprv_strcpy(lang, str2);
- }
- }
- } else {
- ISO_tag = checkISOLanguage(str1);
- if(ISO_tag) {
- ISO_tag = checkISOCountry(str2);
- if (ISO_tag) {
- lang = uprv_malloc(sizeof(char)*uprv_strlen(str1)+1);
- uprv_memset(lang, 0, sizeof(char)*uprv_strlen(str1)+1);
- uprv_strcpy(lang, str1);
- }
- } else {
- ISO_tag = checkISOLanguage(str2);
- if(ISO_tag) {
- ISO_tag = checkISOCountry(str3);
- if (ISO_tag) {
- lang = uprv_malloc(sizeof(char)*uprv_strlen(str2)+1);
- uprv_memset(lang, 0, sizeof(char)*uprv_strlen(str2)+1);
- uprv_strcpy(lang, str2);
- }
- }
- }
- }
-
- if(str0 != NULL){
- uprv_free(str0);