diff options
author | Alexis211 <alexis211@gmail.com> | 2009-09-15 18:59:24 +0200 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2009-09-15 18:59:24 +0200 |
commit | e2e0f21d932224434cb6121165dc00f0c1bb3bdd (patch) | |
tree | d54e5d2c6cfb3aa734d974728ee1fe5ac97482a2 /Source/Kernel/Library | |
parent | 0211692f62cdd934ea9c802bc5b09d63eb4399af (diff) | |
download | Melon-e2e0f21d932224434cb6121165dc00f0c1bb3bdd.tar.gz Melon-e2e0f21d932224434cb6121165dc00f0c1bb3bdd.zip |
cat command now uses the File class.
Diffstat (limited to 'Source/Kernel/Library')
-rw-r--r-- | Source/Kernel/Library/String.class.cpp | 8 | ||||
-rw-r--r-- | Source/Kernel/Library/WChar.class.cpp | 8 | ||||
-rw-r--r-- | Source/Kernel/Library/WChar.class.h | 18 |
3 files changed, 21 insertions, 13 deletions
diff --git a/Source/Kernel/Library/String.class.cpp b/Source/Kernel/Library/String.class.cpp index 5ee216c..6380b25 100644 --- a/Source/Kernel/Library/String.class.cpp +++ b/Source/Kernel/Library/String.class.cpp @@ -55,7 +55,7 @@ String::String() { } String::String(const char* string) { - m_length = WChar::utf8len(string); + m_length = WChar::utfLen(string); if (m_length == 0) { m_string = 0; return; @@ -101,7 +101,7 @@ void String::operator= (const String &other) { } void String::operator= (const char* string) { - m_length = WChar::utf8len(string); + m_length = WChar::utfLen(string); if (m_string != 0) delete [] m_string; if (m_length == 0) { m_string = 0; @@ -125,7 +125,7 @@ bool String::operator== (const String &other) const { } bool String::operator== (const char* string) const { - if (m_length != WChar::utf8len(string)) return false; + if (m_length != WChar::utfLen(string)) return false; int i = 0, l = strlen(string), c = 0; WChar tmp; while (i < l) { @@ -152,7 +152,7 @@ String& String::operator+= (const String &other) { } String& String::operator+= (const char* other) { - WChar* newdata = new WChar[m_length + WChar::utf8len(other) + 1]; + WChar* newdata = new WChar[m_length + WChar::utfLen(other) + 1]; for (u32int i = 0; i < m_length; i++) { newdata[i] = m_string[i]; } diff --git a/Source/Kernel/Library/WChar.class.cpp b/Source/Kernel/Library/WChar.class.cpp index bb1269d..d7f01de 100644 --- a/Source/Kernel/Library/WChar.class.cpp +++ b/Source/Kernel/Library/WChar.class.cpp @@ -19,11 +19,11 @@ WChar::WChar(char c) { affectAscii(c); } -WChar::WChar(const char* c) { +WChar::WChar(const char* c, u8int encoding) { //TODO : take encoding into account affectUtf8(c); } -u32int WChar::utf8len(const char* c) { +u32int WChar::utfLen(const char* c, u8int encoding) { int i = 0, l = CMem::strlen(c), co = 0; while (i < l) { if ((c[i] & 0x80) == 0) i += 1; @@ -42,10 +42,6 @@ void WChar::affectAscii(char c) { } u32int WChar::affectUtf8(const 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; diff --git a/Source/Kernel/Library/WChar.class.h b/Source/Kernel/Library/WChar.class.h index 9ddccd1..fc00577 100644 --- a/Source/Kernel/Library/WChar.class.h +++ b/Source/Kernel/Library/WChar.class.h @@ -3,20 +3,32 @@ #include <Core/common.wtf.h> +enum { + UE_UTF8, + UE_UTF16, + UE_UTF32, +}; + +union uchar_repr_t { + char c[4]; + u32int i; +}; + struct WChar { u32int value; - static WChar CP437[]; + static WChar CP437[]; //Codepage 437, used for conversion from/to ascii WChar(); //Creates a null character WChar(char c); //From ascii character - WChar(const char* c); //From utf8 string + WChar(const char* c, u8int encoding = UE_UTF8); //From utf8 string - static u32int utf8len(const char* c); //Returns count of utf8 characters in string + static u32int utfLen(const char* c, u8int encoding = UE_UTF8); //Returns count of utf8 characters in string void affectAscii(char c); u32int affectUtf8(const char* c); void affectUtf16(const char* c); void affectUtf32(const char* c); + u8int toAscii(); inline WChar operator+ (u32int other) { |