From 05c932b5acbf3ef97cbb5bb112154435313d764e Mon Sep 17 00:00:00 2001 From: shatty Date: Sat, 26 Jul 2003 21:26:36 +0000 Subject: [PATCH] add character set support git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4088 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/support/CharacterSet.cpp | 72 ++++++++++++++++++ src/kits/support/CharacterSetRoster.cpp | 99 +++++++++++++++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 src/kits/support/CharacterSet.cpp create mode 100644 src/kits/support/CharacterSetRoster.cpp diff --git a/src/kits/support/CharacterSet.cpp b/src/kits/support/CharacterSet.cpp new file mode 100644 index 0000000000..577db141f1 --- /dev/null +++ b/src/kits/support/CharacterSet.cpp @@ -0,0 +1,72 @@ +#include + +namespace BPrivate { + +BCharacterSet::BCharacterSet(uint32 _id, uint32 _MIBenum, const char * _print_name, + const char * _iana_name, const char * _mime_name, + const char ** _aliases) +{ + id = _id; + MIBenum = _MIBenum; + print_name = _print_name; + iana_name = _iana_name; + mime_name = _mime_name; + aliases_count = 0; + while (_aliases[aliases_count] != 0) { + aliases_count++; + } + aliases = _aliases; +} + +uint32 +BCharacterSet::GetFontID() const +{ + return id; +} + +uint32 +BCharacterSet::GetConversionID() const +{ + return id-1; +} + +uint32 +BCharacterSet::GetMIBenum() const +{ + return MIBenum; +} + +const char * +BCharacterSet::GetName() const +{ + return iana_name; +} + +const char * +BCharacterSet::GetPrintName() const +{ + return print_name; +} + +const char * +BCharacterSet::GetMIMEName() const +{ + return mime_name; +} + +int32 +BCharacterSet::CountAliases() const +{ + return aliases_count; +} + +const char * +BCharacterSet::AliasAt(uint32 index) const +{ + if (index >= aliases_count) { + return 0; + } + return aliases[index]; +} + +} diff --git a/src/kits/support/CharacterSetRoster.cpp b/src/kits/support/CharacterSetRoster.cpp new file mode 100644 index 0000000000..2ff2616f23 --- /dev/null +++ b/src/kits/support/CharacterSetRoster.cpp @@ -0,0 +1,99 @@ +#include +#include +#include "character_sets.h" + +namespace BPrivate { + +BCharacterSetRoster::BCharacterSetRoster() +{ + index = 0; +} + +BCharacterSetRoster::~BCharacterSetRoster() +{ + // nothing to do +} + +status_t +BCharacterSetRoster::GetNextCharacterSet(BCharacterSet * charset) +{ + if (charset == 0) { + return B_BAD_VALUE; + } + if (index >= character_sets_by_id_count) { + return B_BAD_VALUE; + } + *charset = *character_sets_by_id[index++]; + return B_NO_ERROR; +} + +status_t +BCharacterSetRoster::RewindCharacterSets() +{ + index = 0; + if (index >= character_sets_by_id_count) { + return B_BAD_VALUE; + } + return B_NO_ERROR; +} + +status_t +BCharacterSetRoster::StartWatching(BMessenger target) +{ + // TODO: implement it + return B_ERROR; +} + +status_t +BCharacterSetRoster::StopWatching(BMessenger target) +{ + // TODO: implement it + return B_ERROR; +} + +const BCharacterSet * +BCharacterSetRoster::GetCharacterSetByFontID(uint32 id) +{ + return character_sets_by_id[id]; +} + +const BCharacterSet * +BCharacterSetRoster::GetCharacterSetByConversionID(uint32 id) +{ + return character_sets_by_id[id+1]; +} + +const BCharacterSet * +BCharacterSetRoster::GetCharacterSetByMIBenum(uint32 MIBenum) +{ + return character_sets_by_MIBenum[MIBenum]; +} + +const BCharacterSet * +BCharacterSetRoster::FindCharacterSetByPrintName(char * name) +{ + for (int id = 0 ; (id < character_sets_by_id_count) ; id++) { + if (strcmp(character_sets_by_id[id]->GetPrintName(),name) == 0) { + return character_sets_by_id[id]; + } + } + return 0; +} + +const BCharacterSet * +BCharacterSetRoster::FindCharacterSetByName(char * name) +{ + for (int id = 0 ; (id < character_sets_by_id_count) ; id++) { + if (strcmp(character_sets_by_id[id]->GetName(),name) == 0) { + return character_sets_by_id[id]; + } + for (int alias = 0 ; (alias < character_sets_by_id[id]->CountAliases()) ; alias++) { + if (strcmp(character_sets_by_id[id]->AliasAt(alias),name) == 0) { + return character_sets_by_id[id]; + } + } + } + return 0; +} + +}