|
From: <tbr...@us...> - 2012-03-20 16:56:06
|
Revision: 223
http://xmlwrapp.svn.sourceforge.net/xmlwrapp/?rev=223&view=rev
Author: tbrowder2
Date: 2012-03-20 16:55:55 +0000 (Tue, 20 Mar 2012)
Log Message:
-----------
replace gunichar with uint32_t
Modified Paths:
--------------
trunk/src/libxmlwrappstring/xmlwrappstring.cc
Modified: trunk/src/libxmlwrappstring/xmlwrappstring.cc
===================================================================
--- trunk/src/libxmlwrappstring/xmlwrappstring.cc 2012-03-20 16:49:59 UTC (rev 222)
+++ trunk/src/libxmlwrappstring/xmlwrappstring.cc 2012-03-20 16:55:55 UTC (rev 223)
@@ -19,6 +19,7 @@
*/
#include <xmlwrappstring/xmlwrappstring.h>
+#include <boost/cstdint.hpp> // uint32_t
#include <algorithm>
#include <iostream>
@@ -33,14 +34,14 @@
using xmlws::xmlwrappstring;
-// Little helper to make the conversion from gunichar to UTF-8 a one-liner.
+// Little helper to make the conversion from uint32_t to UTF-8 a one-liner.
//
struct UnicharToUtf8
{
char buf[6];
xmlwrappstring::size_type len;
- explicit UnicharToUtf8(gunichar uc)
+ explicit UnicharToUtf8(uint32_t uc)
: len (g_unichar_to_utf8(uc, buf)) {}
};
@@ -147,11 +148,11 @@
return xmlwrappstring::npos;
long ucs4_match_size = 0;
- const xmlws::ScopedPtr<gunichar> ucs4_match
+ const xmlws::ScopedPtr<uint32_t> ucs4_match
(g_utf8_to_ucs4_fast(utf8_match, utf8_match_size, &ucs4_match_size));
- const gunichar *const match_begin = ucs4_match.get();
- const gunichar *const match_end = match_begin + ucs4_match_size;
+ const uint32_t *const match_begin = ucs4_match.get();
+ const uint32_t *const match_end = match_begin + ucs4_match_size;
const char *const str_begin = str.data();
const char *const str_end = str_begin + str.size();
@@ -160,7 +161,7 @@
pstr < str_end;
pstr = g_utf8_next_char(pstr))
{
- const gunichar *const pfound = std::find(match_begin, match_end, g_utf8_get_char(pstr));
+ const uint32_t *const pfound = std::find(match_begin, match_end, g_utf8_get_char(pstr));
if((pfound != match_end) != find_not_of)
return offset;
@@ -179,11 +180,11 @@
bool find_not_of)
{
long ucs4_match_size = 0;
- const xmlws::ScopedPtr<gunichar> ucs4_match
+ const xmlws::ScopedPtr<uint32_t> ucs4_match
(g_utf8_to_ucs4_fast(utf8_match, utf8_match_size, &ucs4_match_size));
- const gunichar *const match_begin = ucs4_match.get();
- const gunichar *const match_end = match_begin + ucs4_match_size;
+ const uint32_t *const match_begin = ucs4_match.get();
+ const uint32_t *const match_end = match_begin + ucs4_match_size;
const char *const str_begin = str.data();
const char* pstr = str_begin;
@@ -199,7 +200,7 @@
--pstr;
while((static_cast<unsigned char>(*pstr) & 0xC0u) == 0x80);
- const gunichar *const pfound = std::find(match_begin, match_end, g_utf8_get_char(pstr));
+ const uint32_t *const pfound = std::find(match_begin, match_end, g_utf8_get_char(pstr));
if((pfound != match_end) != find_not_of)
return g_utf8_pointer_to_offset(str_begin, pstr);
@@ -258,7 +259,7 @@
* register moves, the generated code is sufficiently close to the optimum
* with GCC 4.1.2 on x86_64.
*/
-gunichar get_unichar_from_std_iterator(std::string::const_iterator pos)
+uint32_t get_unichar_from_std_iterator(std::string::const_iterator pos)
{
unsigned int result = static_cast<unsigned char>(*pos);
@@ -312,7 +313,7 @@
string_ (src)
{}
-xmlwrappstring::xmlwrappstring(xmlwrappstring::size_type n, gunichar uc)
+xmlwrappstring::xmlwrappstring(xmlwrappstring::size_type n, uint32_t uc)
:
string_ ()
{
@@ -370,7 +371,7 @@
return *this;
}
-xmlwrappstring& xmlwrappstring::operator=(gunichar uc)
+xmlwrappstring& xmlwrappstring::operator=(uint32_t uc)
{
const UnicharToUtf8 conv (uc);
string_.assign(conv.buf, conv.len);
@@ -411,7 +412,7 @@
return *this;
}
-xmlwrappstring& xmlwrappstring::assign(xmlwrappstring::size_type n, gunichar uc)
+xmlwrappstring& xmlwrappstring::assign(xmlwrappstring::size_type n, uint32_t uc)
{
xmlwrappstring temp (n, uc);
string_.swap(temp.string_);
@@ -439,7 +440,7 @@
return *this;
}
-xmlwrappstring& xmlwrappstring::operator+=(gunichar uc)
+xmlwrappstring& xmlwrappstring::operator+=(uint32_t uc)
{
const UnicharToUtf8 conv (uc);
string_.append(conv.buf, conv.len);
@@ -455,7 +456,7 @@
/**** xmlws::xmlwrappstring::push_back() *******************************************/
-void xmlwrappstring::push_back(gunichar uc)
+void xmlwrappstring::push_back(uint32_t uc)
{
const UnicharToUtf8 conv (uc);
string_.append(conv.buf, conv.len);
@@ -494,7 +495,7 @@
return *this;
}
-xmlwrappstring& xmlwrappstring::append(xmlwrappstring::size_type n, gunichar uc)
+xmlwrappstring& xmlwrappstring::append(xmlwrappstring::size_type n, uint32_t uc)
{
string_.append(xmlwrappstring(n, uc).string_);
return *this;
@@ -535,7 +536,7 @@
return *this;
}
-xmlwrappstring& xmlwrappstring::insert(xmlwrappstring::size_type i, xmlwrappstring::size_type n, gunichar uc)
+xmlwrappstring& xmlwrappstring::insert(xmlwrappstring::size_type i, xmlwrappstring::size_type n, uint32_t uc)
{
string_.insert(utf8_byte_offset(string_, i), xmlwrappstring(n, uc).string_);
return *this;
@@ -547,7 +548,7 @@
return *this;
}
-xmlwrappstring::iterator xmlwrappstring::insert(xmlwrappstring::iterator p, gunichar uc)
+xmlwrappstring::iterator xmlwrappstring::insert(xmlwrappstring::iterator p, uint32_t uc)
{
const size_type offset = p.base() - string_.begin();
const UnicharToUtf8 conv (uc);
@@ -560,7 +561,7 @@
return iterator(string_.insert(p.base(), c));
}
-void xmlwrappstring::insert(xmlwrappstring::iterator p, xmlwrappstring::size_type n, gunichar uc)
+void xmlwrappstring::insert(xmlwrappstring::iterator p, xmlwrappstring::size_type n, uint32_t uc)
{
string_.insert(p.base() - string_.begin(), xmlwrappstring(n, uc).string_);
}
@@ -605,7 +606,7 @@
}
xmlwrappstring& xmlwrappstring::replace(xmlwrappstring::size_type i, xmlwrappstring::size_type n,
- xmlwrappstring::size_type n2, gunichar uc)
+ xmlwrappstring::size_type n2, uint32_t uc)
{
const Utf8SubstrBounds bounds (string_, i, n);
string_.replace(bounds.i, bounds.n, xmlwrappstring(n2, uc).string_);
@@ -640,7 +641,7 @@
}
xmlwrappstring& xmlwrappstring::replace(xmlwrappstring::iterator pbegin, xmlwrappstring::iterator pend,
- xmlwrappstring::size_type n, gunichar uc)
+ xmlwrappstring::size_type n, uint32_t uc)
{
string_.replace(pbegin.base(), pend.base(), xmlwrappstring(n, uc).string_);
return *this;
@@ -800,7 +801,7 @@
return utf8_char_offset(string_, string_.find(str, utf8_byte_offset(string_, i)));
}
-xmlwrappstring::size_type xmlwrappstring::find(gunichar uc, xmlwrappstring::size_type i) const
+xmlwrappstring::size_type xmlwrappstring::find(uint32_t uc, xmlwrappstring::size_type i) const
{
const UnicharToUtf8 conv (uc);
return utf8_char_offset(string_, string_.find(conv.buf, utf8_byte_offset(string_, i), conv.len));
@@ -831,7 +832,7 @@
return utf8_char_offset(string_, string_.rfind(str, utf8_byte_offset(string_, i)));
}
-xmlwrappstring::size_type xmlwrappstring::rfind(gunichar uc, xmlwrappstring::size_type i) const
+xmlwrappstring::size_type xmlwrappstring::rfind(uint32_t uc, xmlwrappstring::size_type i) const
{
const UnicharToUtf8 conv (uc);
return utf8_char_offset(string_, string_.rfind(conv.buf, utf8_byte_offset(string_, i), conv.len));
@@ -861,7 +862,7 @@
return utf8_find_first_of(string_, i, match, -1, false);
}
-xmlwrappstring::size_type xmlwrappstring::find_first_of(gunichar uc, xmlwrappstring::size_type i) const
+xmlwrappstring::size_type xmlwrappstring::find_first_of(uint32_t uc, xmlwrappstring::size_type i) const
{
return find(uc, i);
}
@@ -890,7 +891,7 @@
return utf8_find_last_of(string_, i, match, -1, false);
}
-xmlwrappstring::size_type xmlwrappstring::find_last_of(gunichar uc, xmlwrappstring::size_type i) const
+xmlwrappstring::size_type xmlwrappstring::find_last_of(uint32_t uc, xmlwrappstring::size_type i) const
{
return rfind(uc, i);
}
@@ -922,7 +923,7 @@
// Unfortunately, all of the find_*_not_of() methods for single
// characters need their own special implementation.
//
-xmlwrappstring::size_type xmlwrappstring::find_first_not_of(gunichar uc, xmlwrappstring::size_type i) const
+xmlwrappstring::size_type xmlwrappstring::find_first_not_of(uint32_t uc, xmlwrappstring::size_type i) const
{
const size_type bi = utf8_byte_offset(string_, i);
if(bi != npos)
@@ -982,7 +983,7 @@
// Unfortunately, all of the find_*_not_of() methods for single
// characters need their own special implementation.
//
-xmlwrappstring::size_type xmlwrappstring::find_last_not_of(gunichar uc, xmlwrappstring::size_type i) const
+xmlwrappstring::size_type xmlwrappstring::find_last_not_of(uint32_t uc, xmlwrappstring::size_type i) const
{
const char *const pbegin = string_.data();
const char *const pend = pbegin + string_.size();
@@ -1051,7 +1052,7 @@
return string_.max_size();
}
-void xmlwrappstring::resize(xmlwrappstring::size_type n, gunichar uc)
+void xmlwrappstring::resize(xmlwrappstring::size_type n, uint32_t uc)
{
const size_type size_now = size();
if(n < size_now)
@@ -1232,13 +1233,13 @@
/**** xmlws::xmlwrappstring::SequenceToString **************************************/
-xmlwrappstring::SequenceToString<xmlws::xmlwrappstring::iterator,gunichar>
+xmlwrappstring::SequenceToString<xmlws::xmlwrappstring::iterator,uint32_t>
::SequenceToString(xmlws::xmlwrappstring::iterator pbegin, xmlws::xmlwrappstring::iterator pend)
:
std::string(pbegin.base(), pend.base())
{}
-xmlwrappstring::SequenceToString<xmlws::xmlwrappstring::const_iterator,gunichar>
+xmlwrappstring::SequenceToString<xmlws::xmlwrappstring::const_iterator,uint32_t>
::SequenceToString(xmlws::xmlwrappstring::const_iterator pbegin, xmlws::xmlwrappstring::const_iterator pend)
:
std::string(pbegin.base(), pend.base())
@@ -1264,12 +1265,12 @@
# if defined(__STDC_ISO_10646__) && SIZEOF_WCHAR_T == 4
// Avoid going through iconv if wchar_t always contains UCS-4.
glong n_bytes = 0;
- const ScopedPtr<char> buf (g_ucs4_to_utf8(reinterpret_cast<const gunichar*>(str.data()),
+ const ScopedPtr<char> buf (g_ucs4_to_utf8(reinterpret_cast<const uint32_t*>(str.data()),
str.size(), 0, &n_bytes, &error));
# elif defined(G_OS_WIN32) && SIZEOF_WCHAR_T == 2
// Avoid going through iconv if wchar_t always contains UTF-16.
glong n_bytes = 0;
- const ScopedPtr<char> buf (g_utf16_to_utf8(reinterpret_cast<const gunichar2*>(str.data()),
+ const ScopedPtr<char> buf (g_utf16_to_utf8(reinterpret_cast<const uint32_t2*>(str.data()),
str.size(), 0, &n_bytes, &error));
# else
gsize n_bytes = 0;
@@ -1348,12 +1349,12 @@
#if defined(__STDC_ISO_10646__) && SIZEOF_WCHAR_T == 4
// Avoid going through iconv if wchar_t always contains UCS-4.
glong n_bytes = 0;
- const ScopedPtr<char> buf (g_ucs4_to_utf8(reinterpret_cast<const gunichar*>(wstr.data()),
+ const ScopedPtr<char> buf (g_ucs4_to_utf8(reinterpret_cast<const uint32_t*>(wstr.data()),
wstr.size(), 0, &n_bytes, &error));
#elif defined(G_OS_WIN32) && SIZEOF_WCHAR_T == 2
// Avoid going through iconv if wchar_t always contains UTF-16.
glong n_bytes = 0;
- const ScopedPtr<char> buf (g_utf16_to_utf8(reinterpret_cast<const gunichar2*>(wstr.data()),
+ const ScopedPtr<char> buf (g_utf16_to_utf8(reinterpret_cast<const uint32_t2*>(wstr.data()),
wstr.size(), 0, &n_bytes, &error));
#else
gsize n_bytes = 0;
@@ -1378,11 +1379,11 @@
#if defined(__STDC_ISO_10646__) && SIZEOF_WCHAR_T == 4
// Avoid going through iconv if wchar_t always contains UCS-4.
- const ScopedPtr<gunichar> buf (g_utf8_to_ucs4(utf8_string.raw().data(),
+ const ScopedPtr<uint32_t> buf (g_utf8_to_ucs4(utf8_string.raw().data(),
utf8_string.raw().size(), 0, 0, &error));
#elif defined(G_OS_WIN32) && SIZEOF_WCHAR_T == 2
// Avoid going through iconv if wchar_t always contains UTF-16.
- const ScopedPtr<gunichar2> buf (g_utf8_to_utf16(utf8_string.raw().data(),
+ const ScopedPtr<uint32_t2> buf (g_utf8_to_utf16(utf8_string.raw().data(),
utf8_string.raw().size(), 0, 0, &error));
#else
// TODO: For some reason the conversion from UTF-8 to WCHAR_T doesn't work
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|