summaryrefslogtreecommitdiff
path: root/Source/Kernel/Library
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Kernel/Library')
-rw-r--r--Source/Kernel/Library/ByteArray.class.cpp4
-rw-r--r--Source/Kernel/Library/ByteArray.class.h8
-rw-r--r--Source/Kernel/Library/WChar.class.cpp29
-rw-r--r--Source/Kernel/Library/WChar.class.h1
4 files changed, 27 insertions, 15 deletions
diff --git a/Source/Kernel/Library/ByteArray.class.cpp b/Source/Kernel/Library/ByteArray.class.cpp
index b987817..9972493 100644
--- a/Source/Kernel/Library/ByteArray.class.cpp
+++ b/Source/Kernel/Library/ByteArray.class.cpp
@@ -53,11 +53,11 @@ void ByteArray::dump(VirtualTerminal *vt) {
vt->hexDump(m_string, m_length);
}
-ByteArray::operator String () {
+String ByteArray::toString (u8int encoding) {
char* c = new char[m_length + 1];
memcpy((u8int*)c, m_string, m_length);
c[m_length] = 0; //Add NULL terminator
- String r(c);
+ String r(c, encoding);
delete c;
return r;
}
diff --git a/Source/Kernel/Library/ByteArray.class.h b/Source/Kernel/Library/ByteArray.class.h
index 4b2dbed..f5214b3 100644
--- a/Source/Kernel/Library/ByteArray.class.h
+++ b/Source/Kernel/Library/ByteArray.class.h
@@ -7,6 +7,12 @@
class ByteArray : public BasicString<u8int> {
public:
ByteArray() : BasicString<u8int>() {}
+ ByteArray(const BasicString<u8int> &bs) : BasicString<u8int>() {
+ m_length = bs.size();
+ m_string = new u8int[m_length];
+ for (u32int i = 0; i < m_length; i++)
+ m_string[i] = bs[i];
+ }
ByteArray(const ByteArray& other) : BasicString<u8int>(other) {}
ByteArray(const char* c);
ByteArray(u32int size) : BasicString<u8int>((u8int)0, size) {}
@@ -17,7 +23,7 @@ class ByteArray : public BasicString<u8int> {
void dump(VirtualTerminal *vt);
- operator String ();
+ String toString(u8int encoding = UE_UTF8);
operator u8int* () { return m_string; }
};
diff --git a/Source/Kernel/Library/WChar.class.cpp b/Source/Kernel/Library/WChar.class.cpp
index 8b8b2e8..a6ecf3f 100644
--- a/Source/Kernel/Library/WChar.class.cpp
+++ b/Source/Kernel/Library/WChar.class.cpp
@@ -25,21 +25,26 @@ WChar::WChar(const char* c, u8int encoding) {
if (encoding == UE_UTF32) affectUtf32(c);
}
+u32int WChar::ucharLen(const char* c, u8int encoding) {
+ if (encoding == UE_UTF8) {
+ if ((c[0] & 0x80) == 0) return 1;
+ else if ((c[0] & 0xE0) == 0xC0) return 2;
+ else if ((c[0] & 0xF0) == 0xE0) return 3;
+ else if ((c[0] & 0xF8) == 0xF0) return 4;
+ else return 1;
+ } else if (encoding == UE_UTF16) {
+ if ((c[0] & 0xFC) == 0xD8 and (c[2] & 0xFC) == 0xDC) return 4;
+ else return 2;
+ } else if (encoding == UE_UTF32) {
+ return 4;
+ }
+ return 1;
+}
+
u32int WChar::utfLen(const char* c, u8int encoding) {
int i = 0, l = CMem::strlen(c), co = 0;
while (i < l) {
- if (encoding == UE_UTF8) {
- 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;
- } else if (encoding == UE_UTF16) {
- if ((c[i] & 0xFC) == 0xD8 and (c[i + 2] & 0xFC) == 0xDC) i += 4;
- else i += 2;
- } else if (encoding == UE_UTF32) {
- i += 4;
- }
+ i += ucharLen(c + i, encoding);
co++;
}
return co;
diff --git a/Source/Kernel/Library/WChar.class.h b/Source/Kernel/Library/WChar.class.h
index 62226f5..ba94a23 100644
--- a/Source/Kernel/Library/WChar.class.h
+++ b/Source/Kernel/Library/WChar.class.h
@@ -22,6 +22,7 @@ struct WChar {
WChar(char c); //From ascii character
WChar(const char* c, u8int encoding = UE_UTF8); //From utf8 string
+ static u32int ucharLen(const char* c, u8int encoding = UE_UTF8); //Returns count of bytes in one unicode character
static u32int utfLen(const char* c, u8int encoding = UE_UTF8); //Returns count of utf8 characters in string
void affectAscii(char c);