1ec5b4cacSshatty #include <string.h> 23aeed660SJérôme Duval #include <strings.h> 39f0ebaadSshatty #include <CharacterSet.h> 49f0ebaadSshatty #include <CharacterSetRoster.h> 59f0ebaadSshatty #include "character_sets.h" 69f0ebaadSshatty 79f0ebaadSshatty namespace BPrivate { 89f0ebaadSshatty BCharacterSetRoster()99f0ebaadSshattyBCharacterSetRoster::BCharacterSetRoster() 109f0ebaadSshatty { 119f0ebaadSshatty index = 0; 129f0ebaadSshatty } 139f0ebaadSshatty ~BCharacterSetRoster()149f0ebaadSshattyBCharacterSetRoster::~BCharacterSetRoster() 159f0ebaadSshatty { 169f0ebaadSshatty // nothing to do 179f0ebaadSshatty } 189f0ebaadSshatty 199f0ebaadSshatty status_t GetNextCharacterSet(BCharacterSet * charset)209f0ebaadSshattyBCharacterSetRoster::GetNextCharacterSet(BCharacterSet * charset) 219f0ebaadSshatty { 229f0ebaadSshatty if (charset == 0) { 239f0ebaadSshatty return B_BAD_VALUE; 249f0ebaadSshatty } 259f0ebaadSshatty if (index >= character_sets_by_id_count) { 269f0ebaadSshatty return B_BAD_VALUE; 279f0ebaadSshatty } 289f0ebaadSshatty *charset = *character_sets_by_id[index++]; 299f0ebaadSshatty return B_NO_ERROR; 309f0ebaadSshatty } 319f0ebaadSshatty 329f0ebaadSshatty status_t RewindCharacterSets()339f0ebaadSshattyBCharacterSetRoster::RewindCharacterSets() 349f0ebaadSshatty { 359f0ebaadSshatty index = 0; 369f0ebaadSshatty if (index >= character_sets_by_id_count) { 379f0ebaadSshatty return B_BAD_VALUE; 389f0ebaadSshatty } 399f0ebaadSshatty return B_NO_ERROR; 409f0ebaadSshatty } 419f0ebaadSshatty 429f0ebaadSshatty status_t StartWatching(BMessenger target)439f0ebaadSshattyBCharacterSetRoster::StartWatching(BMessenger target) 449f0ebaadSshatty { 459f0ebaadSshatty // TODO: implement it 469f0ebaadSshatty return B_ERROR; 479f0ebaadSshatty } 489f0ebaadSshatty 499f0ebaadSshatty status_t StopWatching(BMessenger target)509f0ebaadSshattyBCharacterSetRoster::StopWatching(BMessenger target) 519f0ebaadSshatty { 529f0ebaadSshatty // TODO: implement it 539f0ebaadSshatty return B_ERROR; 549f0ebaadSshatty } 559f0ebaadSshatty 569f0ebaadSshatty const BCharacterSet * GetCharacterSetByFontID(uint32 id)579f0ebaadSshattyBCharacterSetRoster::GetCharacterSetByFontID(uint32 id) 589f0ebaadSshatty { 59*09a5380dSMurai Takashi if (id >= character_sets_by_id_count) { 609f0ebaadSshatty return NULL; 619f0ebaadSshatty } 629f0ebaadSshatty return character_sets_by_id[id]; 639f0ebaadSshatty } 649f0ebaadSshatty 659f0ebaadSshatty const BCharacterSet * GetCharacterSetByConversionID(uint32 id)669f0ebaadSshattyBCharacterSetRoster::GetCharacterSetByConversionID(uint32 id) 679f0ebaadSshatty { 68*09a5380dSMurai Takashi if (id + 1 >= character_sets_by_id_count) { 699f0ebaadSshatty return NULL; 709f0ebaadSshatty } 719f0ebaadSshatty return character_sets_by_id[id+1]; 729f0ebaadSshatty } 739f0ebaadSshatty 749f0ebaadSshatty const BCharacterSet * GetCharacterSetByMIBenum(uint32 MIBenum)759f0ebaadSshattyBCharacterSetRoster::GetCharacterSetByMIBenum(uint32 MIBenum) 769f0ebaadSshatty { 77*09a5380dSMurai Takashi if (MIBenum > maximum_valid_MIBenum) { 789f0ebaadSshatty return NULL; 799f0ebaadSshatty } 809f0ebaadSshatty return character_sets_by_MIBenum[MIBenum]; 819f0ebaadSshatty } 829f0ebaadSshatty 839f0ebaadSshatty const BCharacterSet * FindCharacterSetByPrintName(const char * name)84ec5b4cacSshattyBCharacterSetRoster::FindCharacterSetByPrintName(const char * name) 859f0ebaadSshatty { 86ec5b4cacSshatty for (uint id = 0 ; (id < character_sets_by_id_count) ; id++) { 879f0ebaadSshatty if (strcmp(character_sets_by_id[id]->GetPrintName(),name) == 0) { 889f0ebaadSshatty return character_sets_by_id[id]; 899f0ebaadSshatty } 909f0ebaadSshatty } 919f0ebaadSshatty return 0; 929f0ebaadSshatty } 939f0ebaadSshatty 949f0ebaadSshatty const BCharacterSet * FindCharacterSetByName(const char * name)95ec5b4cacSshattyBCharacterSetRoster::FindCharacterSetByName(const char * name) 969f0ebaadSshatty { 97d026a4b5Sshatty // first search standard names and mime names 98ec5b4cacSshatty for (uint id = 0 ; (id < character_sets_by_id_count) ; id++) { 99ec5b4cacSshatty if (strcasecmp(character_sets_by_id[id]->GetName(),name) == 0) { 1009f0ebaadSshatty return character_sets_by_id[id]; 1019f0ebaadSshatty } 1029f0ebaadSshatty const char * mime = character_sets_by_id[id]->GetMIMEName(); 103ec5b4cacSshatty if ((mime != NULL) && (strcasecmp(mime,name) == 0)) { 1049f0ebaadSshatty return character_sets_by_id[id]; 1059f0ebaadSshatty } 106d026a4b5Sshatty } 107d026a4b5Sshatty // only after searching all the above names do we look at aliases 108ec5b4cacSshatty for (uint id = 0 ; (id < character_sets_by_id_count) ; id++) { 1099f0ebaadSshatty for (int alias = 0 ; (alias < character_sets_by_id[id]->CountAliases()) ; alias++) { 110ec5b4cacSshatty if (strcasecmp(character_sets_by_id[id]->AliasAt(alias),name) == 0) { 1119f0ebaadSshatty return character_sets_by_id[id]; 1129f0ebaadSshatty } 1139f0ebaadSshatty } 1149f0ebaadSshatty } 1159f0ebaadSshatty return 0; 1169f0ebaadSshatty } 1179f0ebaadSshatty 1189f0ebaadSshatty } 119