30 #define ISO639_BTMAP_ENTRY_SIZE (3+3+1)
31 #define ISO639_BTMAP_ENTRY_COUNT 20
33 #define ISO639_23MAP_ENTRY_SIZE (2+3+1)
34 #define ISO639_23MAP_ENTRY_COUNT (204-ISO639_BTMAP_ENTRY_COUNT)
270 int rc = ((
char *)pkey)[0] - ((
char *)pelem)[0];
273 rc = ((
char *)pkey)[1] - ((
char *)pelem)[1];
288 int rc = ((
char *)pkey)[0] - ((
char *)pelem)[0];
291 rc = ((
char *)pkey)[1] - ((
char *)pelem)[1];
294 rc = ((
char *)pkey)[2] - ((
char *)pelem)[2];
310 const char *rc = (
const char *)bsearch(
311 (
const void *)language3,
313 ISO639_BTMAP_ENTRY_COUNT,
314 ISO639_BTMAP_ENTRY_SIZE,
327 static void MapISO639_TerminologyToBibliographic(
char *language3 )
329 for(
int i=0; i<ISO639_BTMAP_ENTRY_COUNT; i++ )
332 if( memcmp(language3,&entry[3],3)==0 )
334 memcpy( language3, entry, 3 );
346 if( lang[0] && lang[1] )
352 if( useTerminologyVariant )
355 if( normalized!=lang )
357 strcpy( lang, normalized );
362 MapISO639_TerminologyToBibliographic( lang );
369 const char *rc = (
const char *)bsearch(
372 ISO639_23MAP_ENTRY_COUNT,
373 ISO639_23MAP_ENTRY_SIZE,
379 if( !useTerminologyVariant )
381 MapISO639_TerminologyToBibliographic( lang );
387 strcpy( lang,
"und" );
395 size_t len = strlen(lang);
399 for(
int i=0; i<ISO639_23MAP_ENTRY_COUNT; i++ )
402 if( memcmp(key,&entry[2],3)==0 )
410 if( strcmp(lang,
"mul")!=0 )
412 strcpy( lang,
"un" );
427 *lang++ = tolower(code);
436 void iso639map_NormalizeLanguageCode(
char lang[],
LangCodePreference langCodePreference )
441 switch( langCodePreference )
443 case ISO639_NO_LANGCODE_PREFERENCE:
445 case ISO639_PREFER_3_CHAR_BIBLIOGRAPHIC_LANGCODE:
448 case ISO639_PREFER_3_CHAR_TERMINOLOGY_LANGCODE:
451 case ISO639_PREFER_2_CHAR_LANGCODE:
457 #ifdef INCLUDE_ISO639MAP_TESTS
459 static void TestHelper(
const char *lang,
LangCodePreference langCodePreference,
const char *expectedResult )
461 printf(
"%s[", lang );
462 switch( langCodePreference )
464 case ISO639_NO_LANGCODE_PREFERENCE:
465 printf(
"ISO639_NO_LANGCODE_PREFERENCE" );
467 case ISO639_PREFER_3_CHAR_BIBLIOGRAPHIC_LANGCODE:
468 printf(
"ISO639_PREFER_3_CHAR_BIBLIOGRAPHIC_LANGCODE" );
470 case ISO639_PREFER_3_CHAR_TERMINOLOGY_LANGCODE:
471 printf(
"ISO639_PREFER_3_CHAR_TERMINOLOGY_LANGCODE" );
473 case ISO639_PREFER_2_CHAR_LANGCODE:
474 printf(
"ISO639_PREFER_2_CHAR_LANGCODE" );
478 strcpy( temp, lang );
479 iso639map_NormalizeLanguageCode( temp, langCodePreference );
480 printf(
"] -> %s : ", temp );
481 if( strcmp(temp,expectedResult)!=0 )
483 printf(
"FAIL! expected %s\n", expectedResult );
491 void iso639map_Test(
void )
493 TestHelper(
"en", ISO639_NO_LANGCODE_PREFERENCE,
"en" );
494 TestHelper(
"en", ISO639_PREFER_3_CHAR_BIBLIOGRAPHIC_LANGCODE,
"eng" );
495 TestHelper(
"en", ISO639_PREFER_3_CHAR_TERMINOLOGY_LANGCODE,
"eng" );
496 TestHelper(
"en", ISO639_PREFER_2_CHAR_LANGCODE,
"en" );
498 TestHelper(
"eng", ISO639_NO_LANGCODE_PREFERENCE,
"eng" );
499 TestHelper(
"eng", ISO639_PREFER_3_CHAR_BIBLIOGRAPHIC_LANGCODE,
"eng" );
500 TestHelper(
"eng", ISO639_PREFER_3_CHAR_TERMINOLOGY_LANGCODE,
"eng" );
501 TestHelper(
"eng", ISO639_PREFER_2_CHAR_LANGCODE,
"en" );
503 TestHelper(
"de", ISO639_NO_LANGCODE_PREFERENCE,
"de" );
504 TestHelper(
"de", ISO639_PREFER_3_CHAR_BIBLIOGRAPHIC_LANGCODE,
"ger" );
505 TestHelper(
"de", ISO639_PREFER_3_CHAR_TERMINOLOGY_LANGCODE,
"deu" );
506 TestHelper(
"de", ISO639_PREFER_2_CHAR_LANGCODE,
"de" );
508 TestHelper(
"deu", ISO639_NO_LANGCODE_PREFERENCE,
"deu" );
509 TestHelper(
"deu", ISO639_PREFER_3_CHAR_BIBLIOGRAPHIC_LANGCODE,
"ger" );
510 TestHelper(
"deu", ISO639_PREFER_3_CHAR_TERMINOLOGY_LANGCODE,
"deu" );
511 TestHelper(
"deu", ISO639_PREFER_2_CHAR_LANGCODE,
"de" );
513 TestHelper(
"ger", ISO639_NO_LANGCODE_PREFERENCE,
"ger" );
514 TestHelper(
"ger", ISO639_PREFER_3_CHAR_BIBLIOGRAPHIC_LANGCODE,
"ger" );
515 TestHelper(
"ger", ISO639_PREFER_3_CHAR_TERMINOLOGY_LANGCODE,
"deu" );
516 TestHelper(
"ger", ISO639_PREFER_2_CHAR_LANGCODE,
"de" );
519 TestHelper(
"DE", ISO639_NO_LANGCODE_PREFERENCE,
"de" );
520 TestHelper(
"DE", ISO639_PREFER_3_CHAR_BIBLIOGRAPHIC_LANGCODE,
"ger" );
521 TestHelper(
"DE", ISO639_PREFER_3_CHAR_TERMINOLOGY_LANGCODE,
"deu" );
522 TestHelper(
"DE", ISO639_PREFER_2_CHAR_LANGCODE,
"de" );
524 TestHelper(
"DEU", ISO639_NO_LANGCODE_PREFERENCE,
"deu" );
525 TestHelper(
"DEU", ISO639_PREFER_3_CHAR_BIBLIOGRAPHIC_LANGCODE,
"ger" );
526 TestHelper(
"DEU", ISO639_PREFER_3_CHAR_TERMINOLOGY_LANGCODE,
"deu" );
527 TestHelper(
"DEU", ISO639_PREFER_2_CHAR_LANGCODE,
"de" );
529 TestHelper(
"GER", ISO639_NO_LANGCODE_PREFERENCE,
"ger" );
530 TestHelper(
"GER", ISO639_PREFER_3_CHAR_BIBLIOGRAPHIC_LANGCODE,
"ger" );
531 TestHelper(
"GER", ISO639_PREFER_3_CHAR_TERMINOLOGY_LANGCODE,
"deu" );
532 TestHelper(
"GER", ISO639_PREFER_2_CHAR_LANGCODE,
"de" );
535 #endif // INCLUDE_ISO639MAP_TESTS