From 7b0d6ac9f903296c7537cec9ac606d49cb364049 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Fri, 11 Sep 2009 16:22:30 +0200 Subject: Nothing, really --- Source/Kernel/Library/String.class.cpp | 38 ++++++++-------- Source/Kernel/Library/String.class.h | 12 ++--- Source/Kernel/Library/WChar.class.cpp | 80 ++++++++++++++++++++++++++++++++++ Source/Kernel/Library/WChar.class.h | 51 ++++++++++++++++++++++ Source/Kernel/Library/wchar.class.cpp | 80 ---------------------------------- Source/Kernel/Library/wchar.class.h | 51 ---------------------- 6 files changed, 156 insertions(+), 156 deletions(-) create mode 100644 Source/Kernel/Library/WChar.class.cpp create mode 100644 Source/Kernel/Library/WChar.class.h delete mode 100644 Source/Kernel/Library/wchar.class.cpp delete mode 100644 Source/Kernel/Library/wchar.class.h (limited to 'Source/Kernel/Library') diff --git a/Source/Kernel/Library/String.class.cpp b/Source/Kernel/Library/String.class.cpp index 518d8c9..e70d19f 100644 --- a/Source/Kernel/Library/String.class.cpp +++ b/Source/Kernel/Library/String.class.cpp @@ -6,7 +6,7 @@ using namespace CMem; //strlen and memcpy String String::hex(u32int number) { String ret; ret.m_length = 10; - ret.m_string = new wchar[11]; + ret.m_string = new WChar[11]; ret.m_string[0] = '0'; ret.m_string[1] = 'x'; ret.m_string[10] = 0; @@ -35,7 +35,7 @@ String String::number(s32int number) { String ret; ret.m_length = order; - ret.m_string = new wchar[order + 1]; + ret.m_string = new WChar[order + 1]; for (u32int i = order; i > 0; i--) { ret.m_string[i - 1] = numbers[number % 10]; @@ -55,12 +55,12 @@ String::String() { } String::String(char* string) { - m_length = wchar::utf8len(string); + m_length = WChar::utf8len(string); if (m_length == 0) { m_string = 0; return; } - m_string = new wchar[m_length + 1]; + m_string = new WChar[m_length + 1]; int i = 0, l = strlen(string), c = 0; while (i < l) { i += m_string[c].affectUtf8(string + i); @@ -75,7 +75,7 @@ String::String(const String &other) { m_string = 0; return; } - m_string = new wchar[m_length + 1]; + m_string = new WChar[m_length + 1]; for (u32int i = 0; i < m_length; i++) { m_string[i] = other.m_string[i]; } @@ -93,7 +93,7 @@ void String::operator= (const String &other) { m_string = 0; return; } - m_string = new wchar[m_length + 1]; + m_string = new WChar[m_length + 1]; for (u32int i = 0; i < m_length; i++) { m_string[i] = other.m_string[i]; } @@ -101,13 +101,13 @@ void String::operator= (const String &other) { } void String::operator= (char* string) { - m_length = wchar::utf8len(string); + m_length = WChar::utf8len(string); if (m_string != 0) delete [] m_string; if (m_length == 0) { m_string = 0; return; } - m_string = new wchar[m_length + 1]; + m_string = new WChar[m_length + 1]; int i = 0, l = strlen(string), c = 0; while (i < l) { i += m_string[c].affectUtf8(string + i); @@ -125,9 +125,9 @@ bool String::operator== (String &other) { } bool String::operator== (char* string) { - if (m_length != wchar::utf8len(string)) return false; + if (m_length != WChar::utf8len(string)) return false; int i = 0, l = strlen(string), c = 0; - wchar tmp; + WChar tmp; while (i < l) { i += tmp.affectUtf8(string + i); if (m_string[c] != tmp) return false; @@ -137,7 +137,7 @@ bool String::operator== (char* string) { } String& String::operator+= (String &other) { - wchar* newdata = new wchar[m_length + other.m_length + 1]; + WChar* newdata = new WChar[m_length + other.m_length + 1]; for (u32int i = 0; i < m_length; i++) { newdata[i] = m_string[i]; } @@ -152,7 +152,7 @@ String& String::operator+= (String &other) { } String& String::operator+= (char* other) { - wchar* newdata = new wchar[m_length + wchar::utf8len(other) + 1]; + WChar* newdata = new WChar[m_length + WChar::utf8len(other) + 1]; for (u32int i = 0; i < m_length; i++) { newdata[i] = m_string[i]; } @@ -168,8 +168,8 @@ String& String::operator+= (char* other) { return *this; } -String& String::operator+= (wchar other) { - wchar* newdata = new wchar[m_length + 2]; +String& String::operator+= (WChar other) { + WChar* newdata = new WChar[m_length + 2]; for (u32int i = 0; i < m_length; i++) { newdata[i] = m_string[i]; } @@ -191,7 +191,7 @@ String& String::operator+ (char* other) { //Can be optimized return (ret += other); } -String& String::operator+ (wchar other) { +String& String::operator+ (WChar other) { String ret(*this); return (ret += other); } @@ -236,7 +236,7 @@ u32int String::toInt16() { return number; } -wchar& String::operator[] (int index) { +WChar& String::operator[] (int index) { return m_string[index]; } @@ -254,7 +254,7 @@ bool String::empty() { return (m_length == 0); } -Vector String::split(wchar c) { +Vector String::split(WChar c) { Vector ret; ret.push(String("")); for (u32int i = 0; i < m_length; i++) { @@ -274,9 +274,9 @@ String String::substr(s32int start, s32int size) { size = 0 - size; } String ret; - ret.m_string = new wchar[size + 1]; + ret.m_string = new WChar[size + 1]; ret.m_length = size; - memcpy((u8int*)ret.m_string, (const u8int*)(m_string + start), size * sizeof(wchar)); + memcpy((u8int*)ret.m_string, (const u8int*)(m_string + start), size * sizeof(WChar)); ret.m_string[size] = 0; return ret; } diff --git a/Source/Kernel/Library/String.class.h b/Source/Kernel/Library/String.class.h index d086b31..ecbc2a0 100644 --- a/Source/Kernel/Library/String.class.h +++ b/Source/Kernel/Library/String.class.h @@ -2,13 +2,13 @@ #define DEF_STRING_CLASS #include -#include +#include template class Vector; class String { private: - wchar *m_string; + WChar *m_string; u32int m_length; public: @@ -27,19 +27,19 @@ class String { bool operator== (char* string); String &operator+= (String &other); String &operator+= (char* other); - String &operator+= (wchar other); + String &operator+= (WChar other); String &operator+ (String &other); String &operator+ (char* other); - String &operator+ (wchar other); + String &operator+ (WChar other); s32int toInt(); u32int toInt16(); //From HEX - wchar& operator[] (int index); + WChar& operator[] (int index); u32int size(); void clear(); bool empty(); - Vector split(wchar c); + Vector split(WChar c); String substr(s32int start, s32int size); }; diff --git a/Source/Kernel/Library/WChar.class.cpp b/Source/Kernel/Library/WChar.class.cpp new file mode 100644 index 0000000..c1a1977 --- /dev/null +++ b/Source/Kernel/Library/WChar.class.cpp @@ -0,0 +1,80 @@ +#include "WChar.class.h" + +WChar WChar::CP437[] = { //These are the UTF8 equivalents for the 128 extra characters of code page 850 + "Ç", "ü", "é", "â", "ä", "à", "å", "ç", "ê", "ë", "è", "ï", "î", "ì", "Ä", "Å", + "É", "æ", "Æ", "ô", "ö", "ò", "û", "ù", "ÿ", "Ö", "Ü", "¢", "£", "¥", "₧", "ƒ", + "á", "í", "ó", "ú", "ñ", "Ñ", "ª", "º", "¿", "⌐", "¬", "½", "¼", "¡", "«", "»", + "░", "▒", "▓", "│", "┤", "╡", "╢", "╖", "╕", "╣", "║", "╗", "╝", "╜", "╛", "┐", + "└", "┴", "┬", "├", "─", "┼", "╞", "╟", "╚", "╔", "╩", "╦", "╠", "═", "╬", "¤", + "╨", "╤", "╥", "╙", "╘", "╒", "╓", "╫", "╪", "┘", "┌", "█", "▄", "▌", "▐", "▀", + "α", "ß", "Γ", "π", "Σ", "σ", "µ", "τ", "Φ", "Θ", "Ω", "δ", "∞", "φ", "ε", "∩", + "≡", "±", "≥", "≤", "⌠", "⌡", "÷", "≈", "°", "∙", "·", "√", "ⁿ", "²", "■", "⍽" +}; + +WChar::WChar() { + value = 0; +} + +WChar::WChar(char c) { + affectAscii(c); +} + +WChar::WChar(char* c) { + affectUtf8(c); +} + +u32int WChar::utf8len(char* c) { + int i = 0, l = CMem::strlen(c), co = 0; + while (i < l) { + if ((c[i] & 0x80) == 0) i += 1; + else if ((c[i] & 0xE0) == 0xC0) i += 2; + else if ((c[i] & 0xF0) == 0xE0) i += 3; + else if ((c[i] & 0xF8) == 0xF0) i += 4; + else i += 1; + co++; + } + return co; +} + +void WChar::affectAscii(char c) { + if (c >= 0) value = c; + else value = CP437[c + 128]; +} + +u32int WChar::affectUtf8(char* c) { //Returns the number of bytes for the character + /*if ((c[0] & 0xB0) == 0x80) { //11000000b == 10000000b, means we are IN a sequence + value = 0; + return 1; + }*/ + if ((c[0] & 0x80) == 0) { + value = c[0]; //0x80 = 10000000b + return 1; + } + if ((c[0] & 0xE0) == 0xC0) { // 11100000b, 11000000b + value = ((c[0] & 0x1F) << 6) | (c[1] & 0x3F); + if (value < 128) value = 0; //Bad value + return 2; + } + if ((c[0] & 0xF0) == 0xE0) { // 11110000b, 11100000b + value = ((c[0] & 0x0F) << 12) | ((c[1] & 0x3F) << 6) | (c[2] & 0x3F); + if (value < 2048) value = 0; //Bad value + if (value >= 0xD800 and value <= 0xDFFF) value = 0; //These values are unallowed + if (value >= 0xFFFE and value <= 0xFFFF) value = 0; + return 3; + } + if ((c[0] & 0xF8) == 0xF0) { // 11111000b, 11110000b + value = ((c[0] & 0x0E) << 18) | ((c[1] & 0x3F) << 12) | ((c[2] & 0x3F) << 6) | (c[3] & 0x3F); + if (value < 65536) value = 0; //Bad value + return 4; + } + value = 0; //Something wrong happenned + return 1; +} + +u8int WChar::toAscii() { + if (value < 128) return (char)value; + for (int i = 0; i < 128; i++) { + if (CP437[i] == value) return (i + 128); + } + return '?'; +} diff --git a/Source/Kernel/Library/WChar.class.h b/Source/Kernel/Library/WChar.class.h new file mode 100644 index 0000000..c582017 --- /dev/null +++ b/Source/Kernel/Library/WChar.class.h @@ -0,0 +1,51 @@ +#ifndef DEF_UCHAR_CLASS_H +#define DEF_UCHAR_CLASS_H + +#include + +struct WChar { + u32int value; + static WChar CP437[]; + + WChar(); //Creates a null character + WChar(char c); //From ascii character + WChar(char* c); //From utf8 string + + static u32int utf8len(char* c); //Returns count of utf8 characters in string + + void affectAscii(char c); + u32int affectUtf8(char* c); + void affectUtf16(char* c); + void affectUtf32(char* c); + u8int toAscii(); + + inline WChar operator+ (u32int other) { + WChar r; + r.value = value + other; + return r; + } + inline WChar operator- (u32int other) { + WChar r; + r.value = value - other; + return r; + } + inline WChar& operator+= (u32int other) { + value += other; + return *this; + } + inline WChar& operator-= (u32int other) { + value -= other; + return *this; + } + inline bool operator== (u32int other) { + return value == other; + } + inline u32int operator= (u32int v) { + value = v; + return v; + } + + inline operator u32int () { return value; } +}; + +#endif diff --git a/Source/Kernel/Library/wchar.class.cpp b/Source/Kernel/Library/wchar.class.cpp deleted file mode 100644 index 3a2ef92..0000000 --- a/Source/Kernel/Library/wchar.class.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include "wchar.class.h" - -wchar wchar::CP437[] = { //These are the UTF8 equivalents for the 128 extra characters of code page 850 - "Ç", "ü", "é", "â", "ä", "à", "å", "ç", "ê", "ë", "è", "ï", "î", "ì", "Ä", "Å", - "É", "æ", "Æ", "ô", "ö", "ò", "û", "ù", "ÿ", "Ö", "Ü", "¢", "£", "¥", "₧", "ƒ", - "á", "í", "ó", "ú", "ñ", "Ñ", "ª", "º", "¿", "⌐", "¬", "½", "¼", "¡", "«", "»", - "░", "▒", "▓", "│", "┤", "╡", "╢", "╖", "╕", "╣", "║", "╗", "╝", "╜", "╛", "┐", - "└", "┴", "┬", "├", "─", "┼", "╞", "╟", "╚", "╔", "╩", "╦", "╠", "═", "╬", "¤", - "╨", "╤", "╥", "╙", "╘", "╒", "╓", "╫", "╪", "┘", "┌", "█", "▄", "▌", "▐", "▀", - "α", "ß", "Γ", "π", "Σ", "σ", "µ", "τ", "Φ", "Θ", "Ω", "δ", "∞", "φ", "ε", "∩", - "≡", "±", "≥", "≤", "⌠", "⌡", "÷", "≈", "°", "∙", "·", "√", "ⁿ", "²", "■", "⍽" -}; - -wchar::wchar() { - value = 0; -} - -wchar::wchar(char c) { - affectAscii(c); -} - -wchar::wchar(char* c) { - affectUtf8(c); -} - -u32int wchar::utf8len(char* c) { - int i = 0, l = CMem::strlen(c), co = 0; - while (i < l) { - if ((c[i] & 0x80) == 0) i += 1; - else if ((c[i] & 0xE0) == 0xC0) i += 2; - else if ((c[i] & 0xF0) == 0xE0) i += 3; - else if ((c[i] & 0xF8) == 0xF0) i += 4; - else i += 1; - co++; - } - return co; -} - -void wchar::affectAscii(char c) { - if (c >= 0) value = c; - else value = CP437[c + 128]; -} - -u32int wchar::affectUtf8(char* c) { //Returns the number of bytes for the character - /*if ((c[0] & 0xB0) == 0x80) { //11000000b == 10000000b, means we are IN a sequence - value = 0; - return 1; - }*/ - if ((c[0] & 0x80) == 0) { - value = c[0]; //0x80 = 10000000b - return 1; - } - if ((c[0] & 0xE0) == 0xC0) { // 11100000b, 11000000b - value = ((c[0] & 0x1F) << 6) | (c[1] & 0x3F); - if (value < 128) value = 0; //Bad value - return 2; - } - if ((c[0] & 0xF0) == 0xE0) { // 11110000b, 11100000b - value = ((c[0] & 0x0F) << 12) | ((c[1] & 0x3F) << 6) | (c[2] & 0x3F); - if (value < 2048) value = 0; //Bad value - if (value >= 0xD800 and value <= 0xDFFF) value = 0; //These values are unallowed - if (value >= 0xFFFE and value <= 0xFFFF) value = 0; - return 3; - } - if ((c[0] & 0xF8) == 0xF0) { // 11111000b, 11110000b - value = ((c[0] & 0x0E) << 18) | ((c[1] & 0x3F) << 12) | ((c[2] & 0x3F) << 6) | (c[3] & 0x3F); - if (value < 65536) value = 0; //Bad value - return 4; - } - value = 0; //Something wrong happenned - return 1; -} - -u8int wchar::toAscii() { - if (value < 128) return (char)value; - for (int i = 0; i < 128; i++) { - if (CP437[i] == value) return (i + 128); - } - return '?'; -} diff --git a/Source/Kernel/Library/wchar.class.h b/Source/Kernel/Library/wchar.class.h deleted file mode 100644 index cadabd0..0000000 --- a/Source/Kernel/Library/wchar.class.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef DEF_UCHAR_CLASS_H -#define DEF_UCHAR_CLASS_H - -#include - -struct wchar { - u32int value; - static wchar CP437[]; - - wchar(); //Creates a null character - wchar(char c); //From ascii character - wchar(char* c); //From utf8 string - - static u32int utf8len(char* c); //Returns count of utf8 characters in string - - void affectAscii(char c); - u32int affectUtf8(char* c); - void affectUtf16(char* c); - void affectUtf32(char* c); - u8int toAscii(); - - inline wchar operator+ (u32int other) { - wchar r; - r.value = value + other; - return r; - } - inline wchar operator- (u32int other) { - wchar r; - r.value = value - other; - return r; - } - inline wchar& operator+= (u32int other) { - value += other; - return *this; - } - inline wchar& operator-= (u32int other) { - value -= other; - return *this; - } - inline bool operator== (u32int other) { - return value == other; - } - inline u32int operator= (u32int v) { - value = v; - return v; - } - - inline operator u32int () { return value; } -}; - -#endif -- cgit v1.2.3