wx/stream.h \
wx/string.h \
wx/stringimpl.h \
+ wx/stringops.h \
wx/strvararg.h \
wx/sysopt.h \
wx/tarstrm.h \
wx/stream.h \
wx/string.h \
wx/stringimpl.h \
+ wx/stringops.h \
wx/strvararg.h \
wx/sysopt.h \
wx/tarstrm.h \
src/common/stream.cpp \
src/common/string.cpp \
src/common/stringimpl.cpp \
+ src/common/stringops.cpp \
src/common/strvararg.cpp \
src/common/sysopt.cpp \
src/common/tarstrm.cpp \
monodll_stream.o \
monodll_string.o \
monodll_stringimpl.o \
+ monodll_stringops.o \
monodll_strvararg.o \
monodll_sysopt.o \
monodll_tarstrm.o \
monolib_stream.o \
monolib_string.o \
monolib_stringimpl.o \
+ monolib_stringops.o \
monolib_strvararg.o \
monolib_sysopt.o \
monolib_tarstrm.o \
basedll_stream.o \
basedll_string.o \
basedll_stringimpl.o \
+ basedll_stringops.o \
basedll_strvararg.o \
basedll_sysopt.o \
basedll_tarstrm.o \
baselib_stream.o \
baselib_string.o \
baselib_stringimpl.o \
+ baselib_stringops.o \
baselib_strvararg.o \
baselib_sysopt.o \
baselib_tarstrm.o \
monodll_stringimpl.o: $(srcdir)/src/common/stringimpl.cpp $(MONODLL_ODEP)
$(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/common/stringimpl.cpp
+monodll_stringops.o: $(srcdir)/src/common/stringops.cpp $(MONODLL_ODEP)
+ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/common/stringops.cpp
+
monodll_strvararg.o: $(srcdir)/src/common/strvararg.cpp $(MONODLL_ODEP)
$(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/common/strvararg.cpp
monolib_stringimpl.o: $(srcdir)/src/common/stringimpl.cpp $(MONOLIB_ODEP)
$(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/common/stringimpl.cpp
+monolib_stringops.o: $(srcdir)/src/common/stringops.cpp $(MONOLIB_ODEP)
+ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/common/stringops.cpp
+
monolib_strvararg.o: $(srcdir)/src/common/strvararg.cpp $(MONOLIB_ODEP)
$(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/common/strvararg.cpp
basedll_stringimpl.o: $(srcdir)/src/common/stringimpl.cpp $(BASEDLL_ODEP)
$(CXXC) -c -o $@ $(BASEDLL_CXXFLAGS) $(srcdir)/src/common/stringimpl.cpp
+basedll_stringops.o: $(srcdir)/src/common/stringops.cpp $(BASEDLL_ODEP)
+ $(CXXC) -c -o $@ $(BASEDLL_CXXFLAGS) $(srcdir)/src/common/stringops.cpp
+
basedll_strvararg.o: $(srcdir)/src/common/strvararg.cpp $(BASEDLL_ODEP)
$(CXXC) -c -o $@ $(BASEDLL_CXXFLAGS) $(srcdir)/src/common/strvararg.cpp
baselib_stringimpl.o: $(srcdir)/src/common/stringimpl.cpp $(BASELIB_ODEP)
$(CXXC) -c -o $@ $(BASELIB_CXXFLAGS) $(srcdir)/src/common/stringimpl.cpp
+baselib_stringops.o: $(srcdir)/src/common/stringops.cpp $(BASELIB_ODEP)
+ $(CXXC) -c -o $@ $(BASELIB_CXXFLAGS) $(srcdir)/src/common/stringops.cpp
+
baselib_strvararg.o: $(srcdir)/src/common/strvararg.cpp $(BASELIB_ODEP)
$(CXXC) -c -o $@ $(BASELIB_CXXFLAGS) $(srcdir)/src/common/strvararg.cpp
src/common/stream.cpp
src/common/string.cpp
src/common/stringimpl.cpp
+ src/common/stringops.cpp
src/common/strvararg.cpp
src/common/sysopt.cpp
src/common/tarstrm.cpp
wx/stream.h
wx/string.h
wx/stringimpl.h
+ wx/stringops.h
wx/strvararg.h
wx/sysopt.h
wx/tarstrm.h
$(OBJS)\monodll_stream.obj \
$(OBJS)\monodll_string.obj \
$(OBJS)\monodll_stringimpl.obj \
+ $(OBJS)\monodll_stringops.obj \
$(OBJS)\monodll_strvararg.obj \
$(OBJS)\monodll_sysopt.obj \
$(OBJS)\monodll_tarstrm.obj \
$(OBJS)\monolib_stream.obj \
$(OBJS)\monolib_string.obj \
$(OBJS)\monolib_stringimpl.obj \
+ $(OBJS)\monolib_stringops.obj \
$(OBJS)\monolib_strvararg.obj \
$(OBJS)\monolib_sysopt.obj \
$(OBJS)\monolib_tarstrm.obj \
$(OBJS)\basedll_stream.obj \
$(OBJS)\basedll_string.obj \
$(OBJS)\basedll_stringimpl.obj \
+ $(OBJS)\basedll_stringops.obj \
$(OBJS)\basedll_strvararg.obj \
$(OBJS)\basedll_sysopt.obj \
$(OBJS)\basedll_tarstrm.obj \
$(OBJS)\baselib_stream.obj \
$(OBJS)\baselib_string.obj \
$(OBJS)\baselib_stringimpl.obj \
+ $(OBJS)\baselib_stringops.obj \
$(OBJS)\baselib_strvararg.obj \
$(OBJS)\baselib_sysopt.obj \
$(OBJS)\baselib_tarstrm.obj \
$(OBJS)\monodll_stringimpl.obj: ..\..\src\common\stringimpl.cpp
$(CXX) -q -c -P -o$@ $(MONODLL_CXXFLAGS) $**
+$(OBJS)\monodll_stringops.obj: ..\..\src\common\stringops.cpp
+ $(CXX) -q -c -P -o$@ $(MONODLL_CXXFLAGS) $**
+
$(OBJS)\monodll_strvararg.obj: ..\..\src\common\strvararg.cpp
$(CXX) -q -c -P -o$@ $(MONODLL_CXXFLAGS) $**
$(OBJS)\monolib_stringimpl.obj: ..\..\src\common\stringimpl.cpp
$(CXX) -q -c -P -o$@ $(MONOLIB_CXXFLAGS) $**
+$(OBJS)\monolib_stringops.obj: ..\..\src\common\stringops.cpp
+ $(CXX) -q -c -P -o$@ $(MONOLIB_CXXFLAGS) $**
+
$(OBJS)\monolib_strvararg.obj: ..\..\src\common\strvararg.cpp
$(CXX) -q -c -P -o$@ $(MONOLIB_CXXFLAGS) $**
$(OBJS)\basedll_stringimpl.obj: ..\..\src\common\stringimpl.cpp
$(CXX) -q -c -P -o$@ $(BASEDLL_CXXFLAGS) $**
+$(OBJS)\basedll_stringops.obj: ..\..\src\common\stringops.cpp
+ $(CXX) -q -c -P -o$@ $(BASEDLL_CXXFLAGS) $**
+
$(OBJS)\basedll_strvararg.obj: ..\..\src\common\strvararg.cpp
$(CXX) -q -c -P -o$@ $(BASEDLL_CXXFLAGS) $**
$(OBJS)\baselib_stringimpl.obj: ..\..\src\common\stringimpl.cpp
$(CXX) -q -c -P -o$@ $(BASELIB_CXXFLAGS) $**
+$(OBJS)\baselib_stringops.obj: ..\..\src\common\stringops.cpp
+ $(CXX) -q -c -P -o$@ $(BASELIB_CXXFLAGS) $**
+
$(OBJS)\baselib_strvararg.obj: ..\..\src\common\strvararg.cpp
$(CXX) -q -c -P -o$@ $(BASELIB_CXXFLAGS) $**
$(OBJS)\monodll_stream.o \
$(OBJS)\monodll_string.o \
$(OBJS)\monodll_stringimpl.o \
+ $(OBJS)\monodll_stringops.o \
$(OBJS)\monodll_strvararg.o \
$(OBJS)\monodll_sysopt.o \
$(OBJS)\monodll_tarstrm.o \
$(OBJS)\monolib_stream.o \
$(OBJS)\monolib_string.o \
$(OBJS)\monolib_stringimpl.o \
+ $(OBJS)\monolib_stringops.o \
$(OBJS)\monolib_strvararg.o \
$(OBJS)\monolib_sysopt.o \
$(OBJS)\monolib_tarstrm.o \
$(OBJS)\basedll_stream.o \
$(OBJS)\basedll_string.o \
$(OBJS)\basedll_stringimpl.o \
+ $(OBJS)\basedll_stringops.o \
$(OBJS)\basedll_strvararg.o \
$(OBJS)\basedll_sysopt.o \
$(OBJS)\basedll_tarstrm.o \
$(OBJS)\baselib_stream.o \
$(OBJS)\baselib_string.o \
$(OBJS)\baselib_stringimpl.o \
+ $(OBJS)\baselib_stringops.o \
$(OBJS)\baselib_strvararg.o \
$(OBJS)\baselib_sysopt.o \
$(OBJS)\baselib_tarstrm.o \
$(OBJS)\monodll_stringimpl.o: ../../src/common/stringimpl.cpp
$(CXX) -c -o $@ $(MONODLL_CXXFLAGS) $(CPPDEPS) $<
+$(OBJS)\monodll_stringops.o: ../../src/common/stringops.cpp
+ $(CXX) -c -o $@ $(MONODLL_CXXFLAGS) $(CPPDEPS) $<
+
$(OBJS)\monodll_strvararg.o: ../../src/common/strvararg.cpp
$(CXX) -c -o $@ $(MONODLL_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\monolib_stringimpl.o: ../../src/common/stringimpl.cpp
$(CXX) -c -o $@ $(MONOLIB_CXXFLAGS) $(CPPDEPS) $<
+$(OBJS)\monolib_stringops.o: ../../src/common/stringops.cpp
+ $(CXX) -c -o $@ $(MONOLIB_CXXFLAGS) $(CPPDEPS) $<
+
$(OBJS)\monolib_strvararg.o: ../../src/common/strvararg.cpp
$(CXX) -c -o $@ $(MONOLIB_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\basedll_stringimpl.o: ../../src/common/stringimpl.cpp
$(CXX) -c -o $@ $(BASEDLL_CXXFLAGS) $(CPPDEPS) $<
+$(OBJS)\basedll_stringops.o: ../../src/common/stringops.cpp
+ $(CXX) -c -o $@ $(BASEDLL_CXXFLAGS) $(CPPDEPS) $<
+
$(OBJS)\basedll_strvararg.o: ../../src/common/strvararg.cpp
$(CXX) -c -o $@ $(BASEDLL_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\baselib_stringimpl.o: ../../src/common/stringimpl.cpp
$(CXX) -c -o $@ $(BASELIB_CXXFLAGS) $(CPPDEPS) $<
+$(OBJS)\baselib_stringops.o: ../../src/common/stringops.cpp
+ $(CXX) -c -o $@ $(BASELIB_CXXFLAGS) $(CPPDEPS) $<
+
$(OBJS)\baselib_strvararg.o: ../../src/common/strvararg.cpp
$(CXX) -c -o $@ $(BASELIB_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\monodll_stream.obj \
$(OBJS)\monodll_string.obj \
$(OBJS)\monodll_stringimpl.obj \
+ $(OBJS)\monodll_stringops.obj \
$(OBJS)\monodll_strvararg.obj \
$(OBJS)\monodll_sysopt.obj \
$(OBJS)\monodll_tarstrm.obj \
$(OBJS)\monolib_stream.obj \
$(OBJS)\monolib_string.obj \
$(OBJS)\monolib_stringimpl.obj \
+ $(OBJS)\monolib_stringops.obj \
$(OBJS)\monolib_strvararg.obj \
$(OBJS)\monolib_sysopt.obj \
$(OBJS)\monolib_tarstrm.obj \
$(OBJS)\basedll_stream.obj \
$(OBJS)\basedll_string.obj \
$(OBJS)\basedll_stringimpl.obj \
+ $(OBJS)\basedll_stringops.obj \
$(OBJS)\basedll_strvararg.obj \
$(OBJS)\basedll_sysopt.obj \
$(OBJS)\basedll_tarstrm.obj \
$(OBJS)\baselib_stream.obj \
$(OBJS)\baselib_string.obj \
$(OBJS)\baselib_stringimpl.obj \
+ $(OBJS)\baselib_stringops.obj \
$(OBJS)\baselib_strvararg.obj \
$(OBJS)\baselib_sysopt.obj \
$(OBJS)\baselib_tarstrm.obj \
-if exist $(LIBDIRNAME)\wx$(PORTNAME)$(WXUNIVNAME)$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_gl.lib del $(LIBDIRNAME)\wx$(PORTNAME)$(WXUNIVNAME)$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_gl.lib
cd ..\..\samples
$(MAKE) -f makefile.vc $(MAKEARGS) clean
- cd "$(MAKEDIR)"
+ cd $(MAKEDIR)
setup_h: $(SETUPHDIR)\wx ..\..\include\wx\$(__SETUP_H_SUBDIR_FILENAMES)\setup.h $(SETUPHDIR)\wx\setup.h $(SETUPHDIR)\wx\msw\rcdefs.h
sub_samples:
cd ..\..\samples
$(MAKE) -f makefile.vc $(MAKEARGS) all
- cd "$(MAKEDIR)"
+ cd $(MAKEDIR)
$(LIBDIRNAME):
if not exist $(LIBDIRNAME) mkdir $(LIBDIRNAME)
$(OBJS)\monodll_stringimpl.obj: ..\..\src\common\stringimpl.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MONODLL_CXXFLAGS) $**
+$(OBJS)\monodll_stringops.obj: ..\..\src\common\stringops.cpp
+ $(CXX) /c /nologo /TP /Fo$@ $(MONODLL_CXXFLAGS) $**
+
$(OBJS)\monodll_strvararg.obj: ..\..\src\common\strvararg.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MONODLL_CXXFLAGS) $**
$(OBJS)\monolib_stringimpl.obj: ..\..\src\common\stringimpl.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MONOLIB_CXXFLAGS) $**
+$(OBJS)\monolib_stringops.obj: ..\..\src\common\stringops.cpp
+ $(CXX) /c /nologo /TP /Fo$@ $(MONOLIB_CXXFLAGS) $**
+
$(OBJS)\monolib_strvararg.obj: ..\..\src\common\strvararg.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MONOLIB_CXXFLAGS) $**
$(OBJS)\basedll_stringimpl.obj: ..\..\src\common\stringimpl.cpp
$(CXX) /c /nologo /TP /Fo$@ $(BASEDLL_CXXFLAGS) $**
+$(OBJS)\basedll_stringops.obj: ..\..\src\common\stringops.cpp
+ $(CXX) /c /nologo /TP /Fo$@ $(BASEDLL_CXXFLAGS) $**
+
$(OBJS)\basedll_strvararg.obj: ..\..\src\common\strvararg.cpp
$(CXX) /c /nologo /TP /Fo$@ $(BASEDLL_CXXFLAGS) $**
$(OBJS)\baselib_stringimpl.obj: ..\..\src\common\stringimpl.cpp
$(CXX) /c /nologo /TP /Fo$@ $(BASELIB_CXXFLAGS) $**
+$(OBJS)\baselib_stringops.obj: ..\..\src\common\stringops.cpp
+ $(CXX) /c /nologo /TP /Fo$@ $(BASELIB_CXXFLAGS) $**
+
$(OBJS)\baselib_strvararg.obj: ..\..\src\common\strvararg.cpp
$(CXX) /c /nologo /TP /Fo$@ $(BASELIB_CXXFLAGS) $**
$(OBJS)\monodll_stream.obj &
$(OBJS)\monodll_string.obj &
$(OBJS)\monodll_stringimpl.obj &
+ $(OBJS)\monodll_stringops.obj &
$(OBJS)\monodll_strvararg.obj &
$(OBJS)\monodll_sysopt.obj &
$(OBJS)\monodll_tarstrm.obj &
$(OBJS)\monolib_stream.obj &
$(OBJS)\monolib_string.obj &
$(OBJS)\monolib_stringimpl.obj &
+ $(OBJS)\monolib_stringops.obj &
$(OBJS)\monolib_strvararg.obj &
$(OBJS)\monolib_sysopt.obj &
$(OBJS)\monolib_tarstrm.obj &
$(OBJS)\basedll_stream.obj &
$(OBJS)\basedll_string.obj &
$(OBJS)\basedll_stringimpl.obj &
+ $(OBJS)\basedll_stringops.obj &
$(OBJS)\basedll_strvararg.obj &
$(OBJS)\basedll_sysopt.obj &
$(OBJS)\basedll_tarstrm.obj &
$(OBJS)\baselib_stream.obj &
$(OBJS)\baselib_string.obj &
$(OBJS)\baselib_stringimpl.obj &
+ $(OBJS)\baselib_stringops.obj &
$(OBJS)\baselib_strvararg.obj &
$(OBJS)\baselib_sysopt.obj &
$(OBJS)\baselib_tarstrm.obj &
$(OBJS)\monodll_stringimpl.obj : .AUTODEPEND ..\..\src\common\stringimpl.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(MONODLL_CXXFLAGS) $<
+$(OBJS)\monodll_stringops.obj : .AUTODEPEND ..\..\src\common\stringops.cpp
+ $(CXX) -bt=nt -zq -fo=$^@ $(MONODLL_CXXFLAGS) $<
+
$(OBJS)\monodll_strvararg.obj : .AUTODEPEND ..\..\src\common\strvararg.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(MONODLL_CXXFLAGS) $<
$(OBJS)\monolib_stringimpl.obj : .AUTODEPEND ..\..\src\common\stringimpl.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(MONOLIB_CXXFLAGS) $<
+$(OBJS)\monolib_stringops.obj : .AUTODEPEND ..\..\src\common\stringops.cpp
+ $(CXX) -bt=nt -zq -fo=$^@ $(MONOLIB_CXXFLAGS) $<
+
$(OBJS)\monolib_strvararg.obj : .AUTODEPEND ..\..\src\common\strvararg.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(MONOLIB_CXXFLAGS) $<
$(OBJS)\basedll_stringimpl.obj : .AUTODEPEND ..\..\src\common\stringimpl.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(BASEDLL_CXXFLAGS) $<
+$(OBJS)\basedll_stringops.obj : .AUTODEPEND ..\..\src\common\stringops.cpp
+ $(CXX) -bt=nt -zq -fo=$^@ $(BASEDLL_CXXFLAGS) $<
+
$(OBJS)\basedll_strvararg.obj : .AUTODEPEND ..\..\src\common\strvararg.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(BASEDLL_CXXFLAGS) $<
$(OBJS)\baselib_stringimpl.obj : .AUTODEPEND ..\..\src\common\stringimpl.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(BASELIB_CXXFLAGS) $<
+$(OBJS)\baselib_stringops.obj : .AUTODEPEND ..\..\src\common\stringops.cpp
+ $(CXX) -bt=nt -zq -fo=$^@ $(BASELIB_CXXFLAGS) $<
+
$(OBJS)\baselib_strvararg.obj : .AUTODEPEND ..\..\src\common\strvararg.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(BASELIB_CXXFLAGS) $<
# End Source File
# Begin Source File
+SOURCE=..\..\src\common\stringops.cpp
+# End Source File
+# Begin Source File
+
SOURCE=..\..\src\common\strvararg.cpp
# End Source File
# Begin Source File
# End Source File
# Begin Source File
+SOURCE=..\..\include\wx\stringops.h
+# End Source File
+# Begin Source File
+
SOURCE=..\..\include\wx\strvararg.h
# End Source File
# Begin Source File
#include "wx/buffer.h" // for wxCharBuffer
#include "wx/strconv.h" // for wxConvertXXX() macros and wxMBConv classes
#include "wx/stringimpl.h"
+#include "wx/stringops.h"
#include "wx/unichar.h"
class WXDLLIMPEXP_BASE wxString;
// buffer for holding temporary substring when using any of the methods
// that take (char*,size_t) or (wchar_t*,size_t) arguments:
- // FIXME-UTF8: This will need changes when UTF8 build is introduced
template<typename T>
struct SubstrBufFromType
{
{ return ConvertStr(str, n, wxConvLibc); }
#endif
- // moves the iterator to the next Unicode character
- static void IncIter(wxStringImpl::iterator& i) { ++i; }
- static void IncIter(wxStringImpl::const_iterator& i) { ++i; }
- // moves the iterator to the previous Unicode character
- static void DecIter(wxStringImpl::iterator& i) { --i; }
- static void DecIter(wxStringImpl::const_iterator& i) { --i; }
- // moves the iterator by n Unicode characters
- static wxStringImpl::iterator AddToIter(wxStringImpl::iterator i, int n)
- { return i + n; }
- static wxStringImpl::const_iterator AddToIter(wxStringImpl::const_iterator i, int n)
- { return i + n; }
- // returns distance of the two iterators in Unicode characters
- static int DiffIters(wxStringImpl::iterator i1, wxStringImpl::iterator i2)
- { return i1 - i2; }
- static int DiffIters(wxStringImpl::const_iterator i1, wxStringImpl::const_iterator i2)
- { return i1 - i2; }
-
- // encodes the character to a form used to represent it in internal
- // representation (returns a string in UTF8 version)
- static wxChar EncodeChar(wxUniChar ch) { return (wxChar)ch; }
- static wxUniChar DecodeChar(wxStringImpl::const_iterator i) { return *i; }
-
// translates position index in wxString to/from index in underlying
// wxStringImpl:
static size_t PosToImpl(size_t pos) { return pos; }
#else // wxUSE_UNICODE_UTF8
- // checks correctness of UTF-8 sequence
- static bool IsValidUtf8String(const char *c);
-#ifdef __WXDEBUG__
- static bool IsValidUtf8LeadByte(unsigned char c);
-#endif
-
- // table of offsets to skip forward when iterating
- static unsigned char ms_utf8IterTable[256];
-
- static void IncIter(wxStringImpl::iterator& i)
- {
- wxASSERT( IsValidUtf8LeadByte(*i) );
- i += ms_utf8IterTable[(unsigned char)*i];
- }
- static void IncIter(wxStringImpl::const_iterator& i)
- {
- wxASSERT( IsValidUtf8LeadByte(*i) );
- i += ms_utf8IterTable[(unsigned char)*i];
- }
-
- static void DecIter(wxStringImpl::iterator& i);
- static void DecIter(wxStringImpl::const_iterator& i);
- static wxStringImpl::iterator AddToIter(wxStringImpl::iterator i, int n);
- static wxStringImpl::const_iterator AddToIter(wxStringImpl::const_iterator i, int n);
- static int DiffIters(wxStringImpl::const_iterator i1, wxStringImpl::const_iterator i2);
- static int DiffIters(wxStringImpl::iterator i1, wxStringImpl::iterator i2);
-
- struct Utf8CharBuffer
- {
- char data[5];
- operator const char*() const { return data; }
- };
- static Utf8CharBuffer EncodeChar(wxUniChar ch);
- // returns n copies of ch encoded in UTF-8 string
- static wxCharBuffer EncodeNChars(size_t n, wxUniChar ch);
-
- // returns the length of UTF-8 encoding of the character with lead byte 'c'
- static size_t GetUtf8CharLength(char c)
- {
- wxASSERT( IsValidUtf8LeadByte(c) );
- return ms_utf8IterTable[(unsigned char)c];
- }
+ // FIXME-UTF8: return as-is without copying under UTF8 locale, return
+ // converted string under other locales - needs wxCharBuffer
+ // changes
+ static wxCharBuffer ImplStr(const char* str,
+ const wxMBConv& conv = wxConvLibc)
+ { return ConvertStr(str, npos, conv).data; }
+ static SubstrBufFromMB ImplStr(const char* str, size_t n,
+ const wxMBConv& conv = wxConvLibc)
+ { return ConvertStr(str, n, conv); }
- // decodes single UTF-8 character from UTF-8 string
- // FIXME-UTF8: move EncodeChar/DecodeChar and other operations to separate
- // class
- static wxUniChar DecodeChar(wxStringImpl::const_iterator i)
- { return wxUniCharRef::DecodeChar(i); }
- friend class WXDLLIMPEXP_BASE wxUniCharRef;
+ static wxCharBuffer ImplStr(const wchar_t* str)
+ { return ConvertStr(str, npos, wxConvUTF8).data; }
+ static SubstrBufFromWC ImplStr(const wchar_t* str, size_t n)
+ { return ConvertStr(str, n, wxConvUTF8); }
size_t PosToImpl(size_t pos) const
{
else
return const_iterator(m_impl.begin() + pos) - begin();
}
-
- // FIXME-UTF8: return as-is without copying under UTF8 locale, return
- // converted string under other locales - needs wxCharBuffer
- // changes
- static wxCharBuffer ImplStr(const char* str,
- const wxMBConv& conv = wxConvLibc)
- { return ConvertStr(str, npos, conv).data; }
- static SubstrBufFromMB ImplStr(const char* str, size_t n,
- const wxMBConv& conv = wxConvLibc)
- { return ConvertStr(str, n, conv); }
-
- static wxCharBuffer ImplStr(const wchar_t* str)
- { return ConvertStr(str, npos, wxConvUTF8).data; }
- static SubstrBufFromWC ImplStr(const wchar_t* str, size_t n)
- { return ConvertStr(str, n, wxConvUTF8); }
#endif // !wxUSE_UNICODE_UTF8/wxUSE_UNICODE_UTF8
public:
reference operator[](size_t n) const { return *(*this + n); } \
\
iterator_name& operator++() \
- { wxString::IncIter(m_cur); return *this; } \
+ { wxStringOperations::IncIter(m_cur); return *this; } \
iterator_name& operator--() \
- { wxString::DecIter(m_cur); return *this; } \
+ { wxStringOperations::DecIter(m_cur); return *this; } \
iterator_name operator++(int) \
{ \
iterator_name tmp = *this; \
- wxString::IncIter(m_cur); \
+ wxStringOperations::IncIter(m_cur); \
return tmp; \
} \
iterator_name operator--(int) \
{ \
iterator_name tmp = *this; \
- wxString::DecIter(m_cur); \
+ wxStringOperations::DecIter(m_cur); \
return tmp; \
} \
\
iterator_name& operator+=(int n) \
- { m_cur = wxString::AddToIter(m_cur, n); return *this; } \
+ { \
+ m_cur = wxStringOperations::AddToIter(m_cur, n); \
+ return *this; \
+ } \
iterator_name& operator+=(size_t n) \
- { m_cur = wxString::AddToIter(m_cur, (int)n); return *this; } \
+ { \
+ m_cur = wxStringOperations::AddToIter(m_cur, (int)n); \
+ return *this; \
+ } \
iterator_name& operator-=(int n) \
- { m_cur = wxString::AddToIter(m_cur, -n); return *this; } \
+ { \
+ m_cur = wxStringOperations::AddToIter(m_cur, -n); \
+ return *this; \
+ } \
iterator_name& operator-=(size_t n) \
- { m_cur = wxString::AddToIter(m_cur, -(int)n); return *this; } \
+ { \
+ m_cur = wxStringOperations::AddToIter(m_cur, -(int)n); \
+ return *this; \
+ } \
\
difference_type operator-(const iterator_name& i) const \
- { return wxString::DiffIters(m_cur, i.m_cur); } \
+ { return wxStringOperations::DiffIters(m_cur, i.m_cur); } \
\
bool operator==(const iterator_name& i) const \
{ return m_cur == i.m_cur; } \
iterator(const iterator& i) : m_cur(i.m_cur), m_str(i.m_str) {}
iterator operator+(int n) const
- { return iterator(m_str, wxString::AddToIter(m_cur, n)); }
+ { return iterator(m_str, wxStringOperations::AddToIter(m_cur, n)); }
iterator operator+(size_t n) const
- { return iterator(m_str, wxString::AddToIter(m_cur, (int)n)); }
+ { return iterator(m_str, wxStringOperations::AddToIter(m_cur, (int)n)); }
iterator operator-(int n) const
- { return iterator(m_str, wxString::AddToIter(m_cur, -n)); }
+ { return iterator(m_str, wxStringOperations::AddToIter(m_cur, -n)); }
iterator operator-(size_t n) const
- { return iterator(m_str, wxString::AddToIter(m_cur, -(int)n)); }
+ { return iterator(m_str, wxStringOperations::AddToIter(m_cur, -(int)n)); }
private:
iterator(wxString *str, underlying_iterator ptr)
iterator(const iterator& i) : m_cur(i.m_cur) {}
iterator operator+(int n) const
- { return iterator(wxString::AddToIter(m_cur, n)); }
+ { return iterator(wxStringOperations::AddToIter(m_cur, n)); }
iterator operator+(size_t n) const
- { return iterator(wxString::AddToIter(m_cur, (int)n)); }
+ { return iterator(wxStringOperations::AddToIter(m_cur, (int)n)); }
iterator operator-(int n) const
- { return iterator(wxString::AddToIter(m_cur, -n)); }
+ { return iterator(wxStringOperations::AddToIter(m_cur, -n)); }
iterator operator-(size_t n) const
- { return iterator(wxString::AddToIter(m_cur, -(int)n)); }
+ { return iterator(wxStringOperations::AddToIter(m_cur, -(int)n)); }
private:
// for internal wxString use only:
// NB: reference_type is intentionally value, not reference, the character
// may be encoded differently in wxString data:
WX_STR_ITERATOR_IMPL(const_iterator, const wxChar*, wxUniChar,
- wxString::DecodeChar(m_cur));
+ wxStringOperations::DecodeChar(m_cur));
public:
const_iterator(const const_iterator& i) : m_cur(i.m_cur) {}
const_iterator(const iterator& i) : m_cur(i.m_cur) {}
const_iterator operator+(int n) const
- { return const_iterator(wxString::AddToIter(m_cur, n)); }
+ { return const_iterator(wxStringOperations::AddToIter(m_cur, n)); }
const_iterator operator+(size_t n) const
- { return const_iterator(wxString::AddToIter(m_cur, (int)n)); }
+ { return const_iterator(wxStringOperations::AddToIter(m_cur, (int)n)); }
const_iterator operator-(int n) const
- { return const_iterator(wxString::AddToIter(m_cur, -n)); }
+ { return const_iterator(wxStringOperations::AddToIter(m_cur, -n)); }
const_iterator operator-(size_t n) const
- { return const_iterator(wxString::AddToIter(m_cur, -(int)n)); }
+ { return const_iterator(wxStringOperations::AddToIter(m_cur, -(int)n)); }
private:
// for internal wxString use only:
{ return *this = cstr.AsString(); }
// from a character
wxString& operator=(wxUniChar ch)
- { m_impl = EncodeChar(ch); return *this; }
+ { m_impl = wxStringOperations::EncodeChar(ch); return *this; }
wxString& operator=(wxUniCharRef ch)
{ return operator=((wxUniChar)ch); }
wxString& operator=(char ch)
{
#if wxUSE_UNICODE_UTF8
if ( !ch.IsAscii() )
- m_impl.append(EncodeNChars(n, ch));
+ m_impl.append(wxStringOperations::EncodeNChars(n, ch));
else
#endif
m_impl.append(n, (wxStringCharType)ch);
{
#if wxUSE_UNICODE_UTF8
if ( !ch.IsAscii() )
- m_impl.assign(EncodeNChars(n, ch));
+ m_impl.assign(wxStringOperations::EncodeNChars(n, ch));
else
#endif
m_impl.assign(n, (wxStringCharType)ch);
{
#if wxUSE_UNICODE_UTF8
if ( !ch.IsAscii() )
- m_impl.insert(PosToImpl(nPos), EncodeNChars(n, ch));
+ m_impl.insert(PosToImpl(nPos), wxStringOperations::EncodeNChars(n, ch));
else
#endif
m_impl.insert(PosToImpl(nPos), n, (wxStringCharType)ch);
if ( !ch.IsAscii() )
{
size_t pos = IterToImplPos(it);
- m_impl.insert(pos, EncodeChar(ch));
+ m_impl.insert(pos, wxStringOperations::EncodeChar(ch));
return iterator(this, m_impl.begin() + pos);
}
else
{
#if wxUSE_UNICODE_UTF8
if ( !ch.IsAscii() )
- m_impl.insert(IterToImplPos(it), EncodeNChars(n, ch));
+ m_impl.insert(IterToImplPos(it), wxStringOperations::EncodeNChars(n, ch));
else
#endif
m_impl.insert(it.impl(), n, (wxStringCharType)ch);
PosLenToImpl(nStart, nLen, &from, &len);
#if wxUSE_UNICODE_UTF8
if ( !ch.IsAscii() )
- m_impl.replace(from, len, EncodeNChars(nCount, ch));
+ m_impl.replace(from, len, wxStringOperations::EncodeNChars(nCount, ch));
else
#endif
m_impl.replace(from, len, nCount, (wxStringCharType)ch);
{
#if wxUSE_UNICODE_UTF8
if ( !ch.IsAscii() )
- m_impl.replace(first.impl(), last.impl(), EncodeNChars(n, ch));
+ m_impl.replace(first.impl(), last.impl(),
+ wxStringOperations::EncodeNChars(n, ch));
else
#endif
m_impl.replace(first.impl(), last.impl(), n, (wxStringCharType)ch);
// find the first occurence of character ch after nStart
size_t find(wxUniChar ch, size_t nStart = 0) const
- { return PosFromImpl(m_impl.find(EncodeChar(ch), PosToImpl(nStart))); }
+ {
+ return PosFromImpl(m_impl.find(wxStringOperations::EncodeChar(ch),
+ PosToImpl(nStart)));
+ }
size_t find(wxUniCharRef ch, size_t nStart = 0) const
{ return find(wxUniChar(ch), nStart); }
size_t find(char ch, size_t nStart = 0) const
}
// as find, but from the end
size_t rfind(wxUniChar ch, size_t nStart = npos) const
- { return PosFromImpl(m_impl.rfind(EncodeChar(ch), PosToImpl(nStart))); }
+ {
+ return PosFromImpl(m_impl.rfind(wxStringOperations::EncodeChar(ch),
+ PosToImpl(nStart)));
+ }
size_t rfind(wxUniCharRef ch, size_t nStart = npos) const
{ return rfind(wxUniChar(ch), nStart); }
size_t rfind(char ch, size_t nStart = npos) const
{ m_impl += s.AsString().m_impl; return *this; }
// string += char
wxString& operator+=(wxUniChar ch)
- { m_impl += EncodeChar(ch); return *this; }
+ { m_impl += wxStringOperations::EncodeChar(ch); return *this; }
wxString& operator+=(wxUniCharRef ch) { return *this += wxUniChar(ch); }
wxString& operator+=(int ch) { return *this += wxUniChar(ch); }
wxString& operator+=(char ch) { return *this += wxUniChar(ch); }
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// Name: wx/stringops.h
+// Purpose: implementation of wxString primitive operations
+// Author: Vaclav Slavik
+// Modified by:
+// Created: 2007-04-16
+// RCS-ID: $Id$
+// Copyright: (c) 2007 REA Elektronik GmbH
+// Licence: wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_WXSTRINGOPS_H__
+#define _WX_WXSTRINGOPS_H__
+
+#include "wx/chartype.h"
+#include "wx/stringimpl.h"
+#include "wx/unichar.h"
+
+// This header contains wxStringOperations "namespace" class that implements
+// elementary operations on string data as static methods; wxString methods and
+// iterators are implemented in terms of it. Two implementations are available,
+// one for UTF-8 encoded char* string and one for "raw" wchar_t* strings (or
+// char* in ANSI build).
+
+// FIXME-UTF8: only wchar after we remove ANSI build
+#if wxUSE_UNICODE_WCHAR || !wxUSE_UNICODE
+struct WXDLLIMPEXP_BASE wxStringOperationsWchar
+{
+ // moves the iterator to the next Unicode character
+ static void IncIter(wxStringImpl::iterator& i) { ++i; }
+ static void IncIter(wxStringImpl::const_iterator& i) { ++i; }
+
+ // moves the iterator to the previous Unicode character
+ static void DecIter(wxStringImpl::iterator& i) { --i; }
+ static void DecIter(wxStringImpl::const_iterator& i) { --i; }
+
+ // moves the iterator by n Unicode characters
+ static wxStringImpl::iterator AddToIter(const wxStringImpl::iterator& i, int n)
+ { return i + n; }
+ static wxStringImpl::const_iterator AddToIter(const wxStringImpl::const_iterator& i, int n)
+ { return i + n; }
+
+ // returns distance of the two iterators in Unicode characters
+ static int DiffIters(const wxStringImpl::iterator& i1,
+ const wxStringImpl::iterator& i2)
+ { return i1 - i2; }
+ static int DiffIters(const wxStringImpl::const_iterator& i1,
+ const wxStringImpl::const_iterator& i2)
+ { return i1 - i2; }
+
+ // encodes the character to a form used to represent it in internal
+ // representation (returns a string in UTF8 version)
+ static wxChar EncodeChar(const wxUniChar& ch) { return (wxChar)ch; }
+
+ static wxUniChar DecodeChar(const wxStringImpl::const_iterator& i)
+ { return *i; }
+};
+#endif // wxUSE_UNICODE_WCHAR || !wxUSE_UNICODE
+
+
+#if wxUSE_UNICODE_UTF8
+struct WXDLLIMPEXP_BASE wxStringOperationsUtf8
+{
+ // checks correctness of UTF-8 sequence
+ static bool IsValidUtf8String(const char *c);
+#ifdef __WXDEBUG__
+ static bool IsValidUtf8LeadByte(unsigned char c);
+#endif
+
+ // table of offsets to skip forward when iterating over UTF-8 sequence
+ static unsigned char ms_utf8IterTable[256];
+
+
+ template<typename Iterator>
+ static void IncIter(Iterator& i)
+ {
+ wxASSERT( IsValidUtf8LeadByte(*i) );
+ i += ms_utf8IterTable[(unsigned char)*i];
+ }
+
+ template<typename Iterator>
+ static void DecIter(Iterator& i)
+ {
+ wxASSERT( IsValidUtf8LeadByte(*i) );
+
+ // Non-lead bytes are all in the 0x80..0xBF range (i.e. 10xxxxxx in
+ // binary), so we just have to go back until we hit a byte that is
+ // either < 0x80 (i.e. 0xxxxxxx in binary) or 0xC0..0xFF (11xxxxxx in
+ // binary; this includes some invalid values, but we can ignore it
+ // here, because we assume valid UTF-8 input for the purpose of
+ // efficient implementation).
+ --i;
+ while ( ((*i) & 0xC0) == 0x80 /* 2 highest bits are '10' */ )
+ --i;
+ }
+
+ template<typename Iterator>
+ static Iterator AddToIter(const Iterator& i, int n)
+ {
+ Iterator out(i);
+
+ if ( n > 0 )
+ {
+ for ( int j = 0; j < n; ++j )
+ IncIter(out);
+ }
+ else if ( n < 0 )
+ {
+ for ( int j = 0; j > n; --j )
+ DecIter(out);
+ }
+
+ return out;
+ }
+
+ template<typename Iterator>
+ static int DiffIters(Iterator i1, Iterator i2)
+ {
+ int dist = 0;
+
+ if ( i1 < i2 )
+ {
+ while ( i1 != i2 )
+ {
+ IncIter(i1);
+ dist--;
+ }
+ }
+ else if ( i2 < i1 )
+ {
+ while ( i2 != i1 )
+ {
+ IncIter(i2);
+ dist++;
+ }
+ }
+
+ return dist;
+ }
+
+ // buffer for single UTF-8 character
+ struct Utf8CharBuffer
+ {
+ char data[5];
+ operator const char*() const { return data; }
+ };
+
+ // encodes the character as UTF-8:
+ static Utf8CharBuffer EncodeChar(const wxUniChar& ch);
+
+ // returns n copies of ch encoded in UTF-8 string
+ static wxCharBuffer EncodeNChars(size_t n, const wxUniChar& ch);
+
+ // returns the length of UTF-8 encoding of the character with lead byte 'c'
+ static size_t GetUtf8CharLength(char c)
+ {
+ wxASSERT( IsValidUtf8LeadByte(c) );
+ return ms_utf8IterTable[(unsigned char)c];
+ }
+
+ // decodes single UTF-8 character from UTF-8 string
+ static wxUniChar DecodeChar(wxStringImpl::const_iterator i);
+};
+#endif // wxUSE_UNICODE_UTF8
+
+
+#if wxUSE_UNICODE_UTF8
+typedef wxStringOperationsUtf8 wxStringOperations;
+#else
+typedef wxStringOperationsWchar wxStringOperations;
+#endif
+
+#endif // _WX_WXSTRINGOPS_H_
#endif
private:
- wxUniChar UniChar() const
- {
#if wxUSE_UNICODE_UTF8
- return DecodeChar(m_pos);
+ wxUniChar UniChar() const;
#else
- return *m_pos;
-#endif
- }
-
-#if wxUSE_UNICODE_UTF8
- // FIXME-UTF8: move this to a separate 'string operations' class
- static wxUniChar DecodeChar(wxStringImpl::const_iterator i);
- friend class WXDLLIMPEXP_BASE wxString;
+ wxUniChar UniChar() const { return *m_pos; }
#endif
friend class WXDLLIMPEXP_BASE wxUniChar;
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-/*
- * About ref counting:
- * 1) all empty strings use g_strEmpty, nRefs = -1 (set in Init())
- * 2) AllocBuffer() sets nRefs to 1, Lock() increments it by one
- * 3) Unlock() decrements nRefs and frees memory if it goes to 0
- */
-
// ===========================================================================
// headers, declarations, constants
// ===========================================================================
#if wxUSE_UNICODE_UTF8
-// ---------------------------------------------------------------------------
-// UTF-8 operations
-// ---------------------------------------------------------------------------
-
-//
-// Table 3.1B from Unicode spec: Legal UTF-8 Byte Sequences
-//
-// Code Points | 1st Byte | 2nd Byte | 3rd Byte | 4th Byte |
-// -------------------+----------+----------+----------+----------+
-// U+0000..U+007F | 00..7F | | | |
-// U+0080..U+07FF | C2..DF | 80..BF | | |
-// U+0800..U+0FFF | E0 | A0..BF | 80..BF | |
-// U+1000..U+FFFF | E1..EF | 80..BF | 80..BF | |
-// U+10000..U+3FFFF | F0 | 90..BF | 80..BF | 80..BF |
-// U+40000..U+FFFFF | F1..F3 | 80..BF | 80..BF | 80..BF |
-// U+100000..U+10FFFF | F4 | 80..8F | 80..BF | 80..BF |
-// -------------------+----------+----------+----------+----------+
-
-bool wxString::IsValidUtf8String(const char *str)
-{
- if ( !str )
- return true; // empty string is UTF8 string
-
- const unsigned char *c = (const unsigned char*)str;
-
- for ( ; *c; ++c )
- {
- unsigned char b = *c;
-
- if ( b <= 0x7F ) // 00..7F
- continue;
-
- else if ( b < 0xC2 ) // invalid lead bytes: 80..C1
- return false;
-
- // two-byte sequences:
- else if ( b <= 0xDF ) // C2..DF
- {
- b = *(++c);
- if ( !(b >= 0x80 && b <= 0xBF ) )
- return false;
- }
-
- // three-byte sequences:
- else if ( b == 0xE0 )
- {
- b = *(++c);
- if ( !(b >= 0xA0 && b <= 0xBF ) )
- return false;
- b = *(++c);
- if ( !(b >= 0x80 && b <= 0xBF ) )
- return false;
- }
- else if ( b <= 0xEF ) // E1..EF
- {
- for ( int i = 0; i < 2; ++i )
- {
- b = *(++c);
- if ( !(b >= 0x80 && b <= 0xBF ) )
- return false;
- }
- }
-
- // four-byte sequences:
- else if ( b == 0xF0 )
- {
- b = *(++c);
- if ( !(b >= 0x90 && b <= 0xBF ) )
- return false;
- for ( int i = 0; i < 2; ++i )
- {
- b = *(++c);
- if ( !(b >= 0x80 && b <= 0xBF ) )
- return false;
- }
- }
- else if ( b <= 0xF3 ) // F1..F3
- {
- for ( int i = 0; i < 3; ++i )
- {
- b = *(++c);
- if ( !(b >= 0x80 && b <= 0xBF ) )
- return false;
- }
- }
- else if ( b == 0xF4 )
- {
- b = *(++c);
- if ( !(b >= 0x80 && b <= 0x8F ) )
- return false;
- for ( int i = 0; i < 2; ++i )
- {
- b = *(++c);
- if ( !(b >= 0x80 && b <= 0xBF ) )
- return false;
- }
- }
- else // otherwise, it's invalid lead byte
- return false;
- }
-
- return true;
-}
-
-#ifdef __WXDEBUG__
-/* static */
-bool wxString::IsValidUtf8LeadByte(unsigned char c)
-{
- return (c <= 0x7F) || (c >= 0xC2 && c <= 0xF4);
-}
-#endif
-
-unsigned char wxString::ms_utf8IterTable[256] = {
- // single-byte sequences (ASCII):
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 00..0F
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 10..1F
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 20..2F
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 30..3F
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 40..4F
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 50..5F
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 60..6F
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 70..7F
-
- // these are invalid, we use step 1 to skip
- // over them (should never happen):
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 80..8F
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 90..9F
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A0..AF
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B0..BF
- 1, 1, // C0,C1
-
- // two-byte sequences:
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // C2..CF
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // D0..DF
-
- // three-byte sequences:
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // E0..EF
-
- // four-byte sequences:
- 4, 4, 4, 4, 4, // F0..F4
-
- // these are invalid again (5- or 6-byte
- // sequences and sequences for code points
- // above U+10FFFF, as restricted by RFC 3629):
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F5..FF
-};
-
-/* static */
-void wxString::DecIter(wxStringImpl::const_iterator& i)
-{
- wxASSERT( IsValidUtf8LeadByte(*i) );
-
- // Non-lead bytes are all in the 0x80..0xBF range (i.e. 10xxxxxx in
- // binary), so we just have to go back until we hit a byte that is either
- // < 0x80 (i.e. 0xxxxxxx in binary) or 0xC0..0xFF (11xxxxxx in binary; this
- // includes some invalid values, but we can ignore it here, because we
- // assume valid UTF-8 input for the purpose of efficient implementation).
- --i;
- while ( ((*i) & 0xC0) == 0x80 /* 2 highest bits are '10' */ )
- --i;
-}
-
-/* static */
-void wxString::DecIter(wxStringImpl::iterator& i)
-{
- // FIXME-UTF8: use template instead
- wxASSERT( IsValidUtf8LeadByte(*i) );
- --i;
- while ( ((*i) & 0xC0) == 0x80 /* 2 highest bits are '10' */ )
- --i;
-}
-
-/* static */
-wxStringImpl::const_iterator
-wxString::AddToIter(wxStringImpl::const_iterator i, int n)
-{
- wxStringImpl::const_iterator out(i);
-
- if ( n > 0 )
- {
- for ( int j = 0; j < n; ++j )
- IncIter(out);
- }
- else if ( n < 0 )
- {
- for ( int j = 0; j > n; --j )
- DecIter(out);
- }
-
- return out;
-}
-
-wxStringImpl::iterator
-wxString::AddToIter(wxStringImpl::iterator i, int n)
-{
- // FIXME-UTF8: use template instead
- wxStringImpl::iterator out(i);
-
- if ( n > 0 )
- {
- for ( int j = 0; j < n; ++j )
- IncIter(out);
- }
- else if ( n < 0 )
- {
- for ( int j = 0; j > n; --j )
- DecIter(out);
- }
-
- return out;
-}
-
-
-/* static */
-int wxString::DiffIters(wxStringImpl::const_iterator i1,
- wxStringImpl::const_iterator i2)
-{
- int dist = 0;
-
- if ( i1 < i2 )
- {
- while ( i1 != i2 )
- {
- IncIter(i1);
- dist--;
- }
- }
- else if ( i2 < i1 )
- {
- while ( i2 != i1 )
- {
- IncIter(i2);
- dist++;
- }
- }
-
- return dist;
-}
-
-int wxString::DiffIters(wxStringImpl::iterator i1, wxStringImpl::iterator i2)
-{
- // FIXME-UTF8: use template instead
- int dist = 0;
-
- if ( i1 < i2 )
- {
- while ( i1 != i2 )
- {
- IncIter(i1);
- dist--;
- }
- }
- else if ( i2 < i1 )
- {
- while ( i2 != i1 )
- {
- IncIter(i2);
- dist++;
- }
- }
-
- return dist;
-}
-
-/* static */
-wxString::Utf8CharBuffer wxString::EncodeChar(wxUniChar ch)
-{
- Utf8CharBuffer buf;
- char *out = buf.data;
-
- wxUniChar::value_type code = ch.GetValue();
-
- // Char. number range | UTF-8 octet sequence
- // (hexadecimal) | (binary)
- // ----------------------+---------------------------------------------
- // 0000 0000 - 0000 007F | 0xxxxxxx
- // 0000 0080 - 0000 07FF | 110xxxxx 10xxxxxx
- // 0000 0800 - 0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
- // 0001 0000 - 0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
- //
- // Code point value is stored in bits marked with 'x', lowest-order bit
- // of the value on the right side in the diagram above.
- // (from RFC 3629)
-
- if ( code <= 0x7F )
- {
- out[1] = 0;
- out[0] = (char)code;
- }
- else if ( code <= 0x07FF )
- {
- out[2] = 0;
- // NB: this line takes 6 least significant bits, encodes them as
- // 10xxxxxx and discards them so that the next byte can be encoded:
- out[1] = 0x80 | (code & 0x3F); code >>= 6;
- out[0] = 0xC0 | code;
- }
- else if ( code < 0xFFFF )
- {
- out[3] = 0;
- out[2] = 0x80 | (code & 0x3F); code >>= 6;
- out[1] = 0x80 | (code & 0x3F); code >>= 6;
- out[0] = 0xE0 | code;
- }
- else if ( code <= 0x10FFFF )
- {
- out[4] = 0;
- out[3] = 0x80 | (code & 0x3F); code >>= 6;
- out[2] = 0x80 | (code & 0x3F); code >>= 6;
- out[1] = 0x80 | (code & 0x3F); code >>= 6;
- out[0] = 0xF0 | code;
- }
- else
- {
- wxFAIL_MSG( _T("trying to encode undefined Unicode character") );
- out[0] = 0;
- }
-
- return buf;
-}
-
-/* static */
-wxUniChar wxUniCharRef::DecodeChar(wxStringImpl::const_iterator i)
-{
- wxASSERT( wxString::IsValidUtf8LeadByte(*i) ); // FIXME-UTF8: no "wxString::"
-
- wxUniChar::value_type code = 0;
- size_t len = wxString::GetUtf8CharLength(*i);
- wxASSERT_MSG( len <= 4, _T("invalid UTF-8 sequence length") );
-
- // Char. number range | UTF-8 octet sequence
- // (hexadecimal) | (binary)
- // ----------------------+---------------------------------------------
- // 0000 0000 - 0000 007F | 0xxxxxxx
- // 0000 0080 - 0000 07FF | 110xxxxx 10xxxxxx
- // 0000 0800 - 0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
- // 0001 0000 - 0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
- //
- // Code point value is stored in bits marked with 'x', lowest-order bit
- // of the value on the right side in the diagram above.
- // (from RFC 3629)
-
- // mask to extract lead byte's value ('x' bits above), by sequence's length:
- static const unsigned char s_leadValueMask[4] = { 0x7F, 0x1F, 0x0F, 0x07 };
-#ifdef __WXDEBUG__
- // mask and value of lead byte's most significant bits, by length:
- static const unsigned char s_leadMarkerMask[4] = { 0x80, 0xE0, 0xF0, 0xF8 };
- static const unsigned char s_leadMarkerVal[4] = { 0x00, 0xC0, 0xE0, 0xF0 };
-#endif
-
- // extract the lead byte's value bits:
- wxASSERT_MSG( ((unsigned char)*i & s_leadMarkerMask[len-1]) ==
- s_leadMarkerVal[len-1],
- _T("invalid UTF-8 lead byte") );
- code = (unsigned char)*i & s_leadValueMask[len-1];
-
- // all remaining bytes, if any, are handled in the same way regardless of
- // sequence's length:
- for ( ++i ; len > 1; --len, ++i )
- {
- wxASSERT_MSG( ((unsigned char)*i & 0xC0) == 0x80,
- _T("invalid UTF-8 byte") );
-
- code <<= 6;
- code |= (unsigned char)*i & 0x3F;
- }
-
- return wxUniChar(code);
-}
-
-/* static */
-wxCharBuffer wxString::EncodeNChars(size_t n, wxUniChar ch)
-{
- Utf8CharBuffer once(EncodeChar(ch));
- // the IncIter() table can be used to determine the length of ch's encoding:
- size_t len = ms_utf8IterTable[(unsigned char)once.data[0]];
-
- wxCharBuffer buf(n * len);
- char *ptr = buf.data();
- for ( size_t i = 0; i < n; i++, ptr += len )
- {
- memcpy(ptr, once.data, len);
- }
-
- return buf;
-}
-
-
void wxString::PosLenToImpl(size_t pos, size_t len,
size_t *implPos, size_t *implLen) const
{
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: src/common/stringops.cpp
+// Purpose: implementation of wxString primitive operations
+// Author: Vaclav Slavik
+// Modified by:
+// Created: 2007-04-16
+// RCS-ID: $Id$
+// Copyright: (c) 2007 REA Elektronik GmbH
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+// ===========================================================================
+// headers
+// ===========================================================================
+
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+ #pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+ #include "wx/stringops.h"
+#endif
+
+// ===========================================================================
+// implementation
+// ===========================================================================
+
+#if wxUSE_UNICODE_UTF8
+
+// ---------------------------------------------------------------------------
+// UTF-8 sequences lengths
+// ---------------------------------------------------------------------------
+
+unsigned char wxStringOperationsUtf8::ms_utf8IterTable[256] = {
+ // single-byte sequences (ASCII):
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 00..0F
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 10..1F
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 20..2F
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 30..3F
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 40..4F
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 50..5F
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 60..6F
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 70..7F
+
+ // these are invalid, we use step 1 to skip
+ // over them (should never happen):
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 80..8F
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 90..9F
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // A0..AF
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // B0..BF
+ 1, 1, // C0,C1
+
+ // two-byte sequences:
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // C2..CF
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // D0..DF
+
+ // three-byte sequences:
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // E0..EF
+
+ // four-byte sequences:
+ 4, 4, 4, 4, 4, // F0..F4
+
+ // these are invalid again (5- or 6-byte
+ // sequences and sequences for code points
+ // above U+10FFFF, as restricted by RFC 3629):
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // F5..FF
+};
+
+// ---------------------------------------------------------------------------
+// UTF-8 operations
+// ---------------------------------------------------------------------------
+
+//
+// Table 3.1B from Unicode spec: Legal UTF-8 Byte Sequences
+//
+// Code Points | 1st Byte | 2nd Byte | 3rd Byte | 4th Byte |
+// -------------------+----------+----------+----------+----------+
+// U+0000..U+007F | 00..7F | | | |
+// U+0080..U+07FF | C2..DF | 80..BF | | |
+// U+0800..U+0FFF | E0 | A0..BF | 80..BF | |
+// U+1000..U+FFFF | E1..EF | 80..BF | 80..BF | |
+// U+10000..U+3FFFF | F0 | 90..BF | 80..BF | 80..BF |
+// U+40000..U+FFFFF | F1..F3 | 80..BF | 80..BF | 80..BF |
+// U+100000..U+10FFFF | F4 | 80..8F | 80..BF | 80..BF |
+// -------------------+----------+----------+----------+----------+
+
+bool wxStringOperationsUtf8::IsValidUtf8String(const char *str)
+{
+ if ( !str )
+ return true; // empty string is UTF8 string
+
+ const unsigned char *c = (const unsigned char*)str;
+
+ for ( ; *c; ++c )
+ {
+ unsigned char b = *c;
+
+ if ( b <= 0x7F ) // 00..7F
+ continue;
+
+ else if ( b < 0xC2 ) // invalid lead bytes: 80..C1
+ return false;
+
+ // two-byte sequences:
+ else if ( b <= 0xDF ) // C2..DF
+ {
+ b = *(++c);
+ if ( !(b >= 0x80 && b <= 0xBF ) )
+ return false;
+ }
+
+ // three-byte sequences:
+ else if ( b == 0xE0 )
+ {
+ b = *(++c);
+ if ( !(b >= 0xA0 && b <= 0xBF ) )
+ return false;
+ b = *(++c);
+ if ( !(b >= 0x80 && b <= 0xBF ) )
+ return false;
+ }
+ else if ( b <= 0xEF ) // E1..EF
+ {
+ for ( int i = 0; i < 2; ++i )
+ {
+ b = *(++c);
+ if ( !(b >= 0x80 && b <= 0xBF ) )
+ return false;
+ }
+ }
+
+ // four-byte sequences:
+ else if ( b == 0xF0 )
+ {
+ b = *(++c);
+ if ( !(b >= 0x90 && b <= 0xBF ) )
+ return false;
+ for ( int i = 0; i < 2; ++i )
+ {
+ b = *(++c);
+ if ( !(b >= 0x80 && b <= 0xBF ) )
+ return false;
+ }
+ }
+ else if ( b <= 0xF3 ) // F1..F3
+ {
+ for ( int i = 0; i < 3; ++i )
+ {
+ b = *(++c);
+ if ( !(b >= 0x80 && b <= 0xBF ) )
+ return false;
+ }
+ }
+ else if ( b == 0xF4 )
+ {
+ b = *(++c);
+ if ( !(b >= 0x80 && b <= 0x8F ) )
+ return false;
+ for ( int i = 0; i < 2; ++i )
+ {
+ b = *(++c);
+ if ( !(b >= 0x80 && b <= 0xBF ) )
+ return false;
+ }
+ }
+ else // otherwise, it's invalid lead byte
+ return false;
+ }
+
+ return true;
+}
+
+#ifdef __WXDEBUG__
+bool wxStringOperationsUtf8::IsValidUtf8LeadByte(unsigned char c)
+{
+ return (c <= 0x7F) || (c >= 0xC2 && c <= 0xF4);
+}
+#endif
+
+
+wxStringOperationsUtf8::Utf8CharBuffer
+wxStringOperationsUtf8::EncodeChar(const wxUniChar& ch)
+{
+ Utf8CharBuffer buf;
+ char *out = buf.data;
+
+ wxUniChar::value_type code = ch.GetValue();
+
+ // Char. number range | UTF-8 octet sequence
+ // (hexadecimal) | (binary)
+ // ----------------------+---------------------------------------------
+ // 0000 0000 - 0000 007F | 0xxxxxxx
+ // 0000 0080 - 0000 07FF | 110xxxxx 10xxxxxx
+ // 0000 0800 - 0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
+ // 0001 0000 - 0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
+ //
+ // Code point value is stored in bits marked with 'x', lowest-order bit
+ // of the value on the right side in the diagram above.
+ // (from RFC 3629)
+
+ if ( code <= 0x7F )
+ {
+ out[1] = 0;
+ out[0] = (char)code;
+ }
+ else if ( code <= 0x07FF )
+ {
+ out[2] = 0;
+ // NB: this line takes 6 least significant bits, encodes them as
+ // 10xxxxxx and discards them so that the next byte can be encoded:
+ out[1] = 0x80 | (code & 0x3F); code >>= 6;
+ out[0] = 0xC0 | code;
+ }
+ else if ( code < 0xFFFF )
+ {
+ out[3] = 0;
+ out[2] = 0x80 | (code & 0x3F); code >>= 6;
+ out[1] = 0x80 | (code & 0x3F); code >>= 6;
+ out[0] = 0xE0 | code;
+ }
+ else if ( code <= 0x10FFFF )
+ {
+ out[4] = 0;
+ out[3] = 0x80 | (code & 0x3F); code >>= 6;
+ out[2] = 0x80 | (code & 0x3F); code >>= 6;
+ out[1] = 0x80 | (code & 0x3F); code >>= 6;
+ out[0] = 0xF0 | code;
+ }
+ else
+ {
+ wxFAIL_MSG( _T("trying to encode undefined Unicode character") );
+ out[0] = 0;
+ }
+
+ return buf;
+}
+
+wxUniChar
+wxStringOperationsUtf8::DecodeChar(wxStringImpl::const_iterator i)
+{
+ wxASSERT( IsValidUtf8LeadByte(*i) );
+
+ wxUniChar::value_type code = 0;
+ size_t len = GetUtf8CharLength(*i);
+ wxASSERT_MSG( len <= 4, _T("invalid UTF-8 sequence length") );
+
+ // Char. number range | UTF-8 octet sequence
+ // (hexadecimal) | (binary)
+ // ----------------------+---------------------------------------------
+ // 0000 0000 - 0000 007F | 0xxxxxxx
+ // 0000 0080 - 0000 07FF | 110xxxxx 10xxxxxx
+ // 0000 0800 - 0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
+ // 0001 0000 - 0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
+ //
+ // Code point value is stored in bits marked with 'x', lowest-order bit
+ // of the value on the right side in the diagram above.
+ // (from RFC 3629)
+
+ // mask to extract lead byte's value ('x' bits above), by sequence's length:
+ static const unsigned char s_leadValueMask[4] = { 0x7F, 0x1F, 0x0F, 0x07 };
+#ifdef __WXDEBUG__
+ // mask and value of lead byte's most significant bits, by length:
+ static const unsigned char s_leadMarkerMask[4] = { 0x80, 0xE0, 0xF0, 0xF8 };
+ static const unsigned char s_leadMarkerVal[4] = { 0x00, 0xC0, 0xE0, 0xF0 };
+#endif
+
+ // extract the lead byte's value bits:
+ wxASSERT_MSG( ((unsigned char)*i & s_leadMarkerMask[len-1]) ==
+ s_leadMarkerVal[len-1],
+ _T("invalid UTF-8 lead byte") );
+ code = (unsigned char)*i & s_leadValueMask[len-1];
+
+ // all remaining bytes, if any, are handled in the same way regardless of
+ // sequence's length:
+ for ( ++i ; len > 1; --len, ++i )
+ {
+ wxASSERT_MSG( ((unsigned char)*i & 0xC0) == 0x80,
+ _T("invalid UTF-8 byte") );
+
+ code <<= 6;
+ code |= (unsigned char)*i & 0x3F;
+ }
+
+ return wxUniChar(code);
+}
+
+wxCharBuffer wxStringOperationsUtf8::EncodeNChars(size_t n, const wxUniChar& ch)
+{
+ Utf8CharBuffer once(EncodeChar(ch));
+ // the IncIter() table can be used to determine the length of ch's encoding:
+ size_t len = ms_utf8IterTable[(unsigned char)once.data[0]];
+
+ wxCharBuffer buf(n * len);
+ char *ptr = buf.data();
+ for ( size_t i = 0; i < n; i++, ptr += len )
+ {
+ memcpy(ptr, once.data, len);
+ }
+
+ return buf;
+}
+
+#endif // wxUSE_UNICODE_UTF8
#endif
#include "wx/unichar.h"
-
-// FIXME-UTF8: remove once UTF-8 functions moved outside
-#include "wx/string.h"
+#include "wx/stringops.h"
// ===========================================================================
// implementation
// ---------------------------------------------------------------------------
#if wxUSE_UNICODE_UTF8
+wxUniChar wxUniCharRef::UniChar() const
+{
+ return wxStringOperations::DecodeChar(m_pos);
+}
+
wxUniCharRef& wxUniCharRef::operator=(const wxUniChar& c)
{
- wxString::Utf8CharBuffer utf(wxString::EncodeChar(c));
- size_t lenOld = wxString::GetUtf8CharLength(*m_pos);
- size_t lenNew = wxString::GetUtf8CharLength(utf[0]);
+ wxStringOperations::Utf8CharBuffer utf(wxStringOperations::EncodeChar(c));
+ size_t lenOld = wxStringOperations::GetUtf8CharLength(*m_pos);
+ size_t lenNew = wxStringOperations::GetUtf8CharLength(utf[0]);
if ( lenNew == lenOld )
{
wx/stream.h
wx/string.h
wx/stringimpl.h
+wx/stringops.h
wx/strvararg.h
wx/sysopt.h
wx/tarstrm.h
wx/stream.h
wx/string.h
wx/stringimpl.h
+wx/stringops.h
wx/strvararg.h
wx/sysopt.h
wx/tarstrm.h
wx/stream.h
wx/string.h
wx/stringimpl.h
+wx/stringops.h
wx/strvararg.h
wx/sysopt.h
wx/tarstrm.h