1 #include <CharacterSet.h> 2 #include <CharacterSetRoster.h> 3 #include "character_sets.h" 4 5 namespace BPrivate { 6 7 BCharacterSetRoster::BCharacterSetRoster() 8 { 9 index = 0; 10 } 11 12 BCharacterSetRoster::~BCharacterSetRoster() 13 { 14 // nothing to do 15 } 16 17 status_t 18 BCharacterSetRoster::GetNextCharacterSet(BCharacterSet * charset) 19 { 20 if (charset == 0) { 21 return B_BAD_VALUE; 22 } 23 if (index >= character_sets_by_id_count) { 24 return B_BAD_VALUE; 25 } 26 *charset = *character_sets_by_id[index++]; 27 return B_NO_ERROR; 28 } 29 30 status_t 31 BCharacterSetRoster::RewindCharacterSets() 32 { 33 index = 0; 34 if (index >= character_sets_by_id_count) { 35 return B_BAD_VALUE; 36 } 37 return B_NO_ERROR; 38 } 39 40 status_t 41 BCharacterSetRoster::StartWatching(BMessenger target) 42 { 43 // TODO: implement it 44 return B_ERROR; 45 } 46 47 status_t 48 BCharacterSetRoster::StopWatching(BMessenger target) 49 { 50 // TODO: implement it 51 return B_ERROR; 52 } 53 54 const BCharacterSet * 55 BCharacterSetRoster::GetCharacterSetByFontID(uint32 id) 56 { 57 if ((id < 0) || (id >= character_sets_by_id_count)) { 58 return NULL; 59 } 60 return character_sets_by_id[id]; 61 } 62 63 const BCharacterSet * 64 BCharacterSetRoster::GetCharacterSetByConversionID(uint32 id) 65 { 66 if ((id+1 < 0) || (id+1 >= character_sets_by_id_count)) { 67 return NULL; 68 } 69 return character_sets_by_id[id+1]; 70 } 71 72 const BCharacterSet * 73 BCharacterSetRoster::GetCharacterSetByMIBenum(uint32 MIBenum) 74 { 75 if ((MIBenum < 0) || (MIBenum > maximum_valid_MIBenum)) { 76 return NULL; 77 } 78 return character_sets_by_MIBenum[MIBenum]; 79 } 80 81 const BCharacterSet * 82 BCharacterSetRoster::FindCharacterSetByPrintName(char * name) 83 { 84 for (int id = 0 ; (id < character_sets_by_id_count) ; id++) { 85 if (strcmp(character_sets_by_id[id]->GetPrintName(),name) == 0) { 86 return character_sets_by_id[id]; 87 } 88 } 89 return 0; 90 } 91 92 const BCharacterSet * 93 BCharacterSetRoster::FindCharacterSetByName(char * name) 94 { 95 for (int id = 0 ; (id < character_sets_by_id_count) ; id++) { 96 if (strcmp(character_sets_by_id[id]->GetName(),name) == 0) { 97 return character_sets_by_id[id]; 98 } 99 const char * mime = character_sets_by_id[id]->GetMIMEName(); 100 if ((mime != NULL) && (strcmp(mime,name) == 0)) { 101 return character_sets_by_id[id]; 102 } 103 for (int alias = 0 ; (alias < character_sets_by_id[id]->CountAliases()) ; alias++) { 104 if (strcmp(character_sets_by_id[id]->AliasAt(alias),name) == 0) { 105 return character_sets_by_id[id]; 106 } 107 } 108 } 109 return 0; 110 } 111 112 } 113