1
0
forked from 0ad/0ad

Realised why putting utf16string into std is a silly idea

This was SVN commit r700.
This commit is contained in:
Ykkrosh 2004-07-11 11:51:27 +00:00
parent 13d7210742
commit d38ed70623
7 changed files with 28 additions and 30 deletions

View File

@ -995,7 +995,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
XMBAttributeList attributes = Element.getAttributes();
// Well first of all we need to determine the type
std::utf16string type = attributes.getNamedItem( pFile->getAttributeID("type") );
utf16string type = attributes.getNamedItem( pFile->getAttributeID("type") );
// Construct object from specified type
// henceforth, we need to do a rollback before aborting.

View File

@ -39,7 +39,7 @@ CStr::CStr(tstring String)
}
#if !(defined(_MSC_VER) && defined(_UNICODE))
CStr::CStr(std::utf16string String)
CStr::CStr(utf16string String)
{
m_String = tstring(String.begin(), String.end());
}

View File

@ -99,7 +99,7 @@ public:
CStr(std::tstring String); // Creates CStr from C++ string
#if !(defined(_MSC_VER) && defined(_UNICODE))
CStr(std::utf16string String); // Creates CStr from UTF16 string, potentially losing data in UTF16->ASCII conversions
CStr(utf16string String); // Creates CStr from UTF16 string, potentially losing data in UTF16->ASCII conversions
#endif
CStr(const TCHAR* String); // Creates CStr from C-Style TCHAR string
CStr(TCHAR Char); // Creates CStr from a TCHAR

View File

@ -1,4 +1,4 @@
// $Id: XeroXMB.cpp,v 1.3 2004/07/10 20:55:55 philip Exp $
// $Id: XeroXMB.cpp,v 1.4 2004/07/11 11:51:10 philip Exp $
#include "precompiled.h"
@ -11,7 +11,7 @@
const int HeaderMagic = 0x30424D58; // = "XMB0" (little-endian)
const char* HeaderMagicStr = "XMB0";
typedef std::utf16string::value_type char16;
typedef utf16string::value_type char16;
// Warning: May contain traces of pointer abuse
@ -162,9 +162,9 @@ XMBAttributeList XMBElement::getAttributes()
);
}
std::utf16string XMBElement::getText()
utf16string XMBElement::getText()
{
return std::utf16string((char16*)(m_Pointer + 24));
return utf16string((char16*)(m_Pointer + 24));
}
@ -194,7 +194,7 @@ XMBElement XMBElementList::item(const int id)
return XMBElement(Pos);
}
std::utf16string XMBAttributeList::getNamedItem(const int AttributeName)
utf16string XMBAttributeList::getNamedItem(const int AttributeName)
{
char* Pos = m_Pointer;
@ -203,12 +203,12 @@ std::utf16string XMBAttributeList::getNamedItem(const int AttributeName)
for (int i = 0; i < Count; ++i)
{
if (*(int*)Pos == AttributeName)
return std::utf16string((char16*)(Pos+8));
return utf16string((char16*)(Pos+8));
Pos += 8 + *(int*)(Pos+4); // Skip over the string
}
// Can't find attribute
return std::utf16string();
return utf16string();
}
XMBAttribute XMBAttributeList::item(const int id)
@ -235,5 +235,5 @@ XMBAttribute XMBAttributeList::item(const int id)
m_LastItemID = id;
m_LastPointer = Pos;
return XMBAttribute(*(int*)Pos, std::utf16string( (char16*)(Pos+8) ));
return XMBAttribute(*(int*)Pos, utf16string( (char16*)(Pos+8) ));
}

View File

@ -1,4 +1,4 @@
/* $Id: XeroXMB.h,v 1.3 2004/07/10 20:55:55 philip Exp $
/* $Id: XeroXMB.h,v 1.4 2004/07/11 11:51:10 philip Exp $
Xeromyces - XMB reading library
@ -151,7 +151,7 @@ public:
int getNodeName();
XMBElementList getChildNodes();
XMBAttributeList getAttributes();
std::utf16string getText();
utf16string getText();
private:
// Pointer to the start of the node
@ -181,11 +181,11 @@ private:
struct XMBAttribute
{
XMBAttribute(int name, std::utf16string value)
XMBAttribute(int name, utf16string value)
: Name(name), Value(value) {};
int Name;
std::utf16string Value;
utf16string Value;
};
class XMBAttributeList
@ -195,7 +195,7 @@ public:
: Count(count), m_Pointer(offset) {};
// Get the attribute value directly (unlike Xerces)
std::utf16string getNamedItem(const int AttributeName);
utf16string getNamedItem(const int AttributeName);
// Returns an attribute by position in the list
XMBAttribute item(const int id);

View File

@ -1,4 +1,4 @@
// $Id: Xeromyces.cpp,v 1.4 2004/07/10 20:33:00 philip Exp $
// $Id: Xeromyces.cpp,v 1.5 2004/07/11 11:51:10 philip Exp $
#include "precompiled.h"
@ -96,12 +96,12 @@ private:
// Convenient storage for the internal tree
typedef struct {
std::string name;
std::utf16string value;
utf16string value;
} XMLAttribute;
typedef struct XMLElement {
std::string name;
std::utf16string text;
utf16string text;
std::vector<XMLElement*> childs;
std::vector<XMLAttribute*> attrs;
} XMLElement;
@ -354,7 +354,7 @@ void XeroHandler::startElement(const XMLCh* const uri, const XMLCh* const localn
XMLAttribute* a = new XMLAttribute;
a->name = attrName;
const XMLCh *tmp = attrs.getValue(i);
a->value = std::utf16string(tmp, tmp+XMLString::stringLen(tmp));
a->value = utf16string(tmp, tmp+XMLString::stringLen(tmp));
e->attrs.push_back(a);
}
@ -372,7 +372,7 @@ void XeroHandler::endElement(const XMLCh* const uri, const XMLCh* const localnam
void XeroHandler::characters(const XMLCh* const chars, const unsigned int length)
{
ElementStack.top()->text += std::utf16string(chars, chars+XMLString::stringLen(chars));
ElementStack.top()->text += utf16string(chars, chars+XMLString::stringLen(chars));
}
@ -441,10 +441,10 @@ void XeroHandler::OutputElement(XMLElement* el)
// Trim excess whitespace
std::wstring whitespaceW = L" \t\r\n";
std::utf16string whitespace (whitespaceW.begin(), whitespaceW.end());
utf16string whitespace (whitespaceW.begin(), whitespaceW.end());
size_t first = el->text.find_first_not_of(whitespace);
if (first == -1) // entirely whitespace
el->text = std::utf16string();
el->text = utf16string();
else
{
size_t last = el->text.find_last_not_of(whitespace);

View File

@ -9,9 +9,7 @@
// with uint16_t (which is also an unsigned short), so just use std::wstring
#ifdef _MSC_VER
namespace std {
typedef wstring utf16string;
}
typedef std::wstring utf16string;
// On Linux, wchar_t is 32-bit, so define a new version of it
#else
@ -19,11 +17,11 @@ namespace std {
#include <string>
#include "types.h"
namespace std {
typedef uint16_t utf16_t;
typedef std::basic_string<utf16_t> utf16string;
typedef std::basic_stringstream<utf16_t> utf16stringstream;
typedef uint16_t utf16_t;
typedef std::basic_string<utf16_t> utf16string;
typedef std::basic_stringstream<utf16_t> utf16stringstream;
namespace std {
template<>
struct char_traits<utf16_t>
{