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