From 8d1e74202626993f8966ec09731f521f24024a7c Mon Sep 17 00:00:00 2001
From: George Hazan <george.hazan@gmail.com>
Date: Sun, 10 Nov 2013 10:05:24 +0000
Subject: - custom bkstring class removed - code cleaning

git-svn-id: http://svn.miranda-ng.org/main/trunk@6852 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
---
 plugins/SmileyAdd/src/SmileyBase.cpp       |    2 +-
 plugins/SmileyAdd/src/anim.cpp             |   24 +-
 plugins/SmileyAdd/src/bkstring.cpp         |  201 --
 plugins/SmileyAdd/src/bkstring.h           |  258 ---
 plugins/SmileyAdd/src/customsmiley.cpp     |   20 +-
 plugins/SmileyAdd/src/customsmiley.h       |    4 +-
 plugins/SmileyAdd/src/download.cpp         |   86 +-
 plugins/SmileyAdd/src/download.h           |    2 +-
 plugins/SmileyAdd/src/general.cpp          |    6 +-
 plugins/SmileyAdd/src/general.h            |    8 +-
 plugins/SmileyAdd/src/imagecache.cpp       |   40 +-
 plugins/SmileyAdd/src/imagecache.h         |   12 +-
 plugins/SmileyAdd/src/options.cpp          |   51 +-
 plugins/SmileyAdd/src/options.h            |   14 +-
 plugins/SmileyAdd/src/regexp/WCMatcher.cpp |  253 ++-
 plugins/SmileyAdd/src/regexp/WCMatcher.h   |   20 +-
 plugins/SmileyAdd/src/regexp/WCPattern.cpp | 2744 ++++++++++++++--------------
 plugins/SmileyAdd/src/regexp/WCPattern.h   | 1196 ++++++------
 plugins/SmileyAdd/src/services.cpp         |   69 +-
 plugins/SmileyAdd/src/smileyroutines.cpp   |   10 +-
 plugins/SmileyAdd/src/smileys.cpp          |  229 ++-
 plugins/SmileyAdd/src/smileys.h            |   98 +-
 plugins/SmileyAdd/src/smltool.cpp          |    4 +-
 23 files changed, 2390 insertions(+), 2961 deletions(-)
 delete mode 100644 plugins/SmileyAdd/src/bkstring.cpp
 delete mode 100644 plugins/SmileyAdd/src/bkstring.h

(limited to 'plugins/SmileyAdd/src')

diff --git a/plugins/SmileyAdd/src/SmileyBase.cpp b/plugins/SmileyAdd/src/SmileyBase.cpp
index 206ee79a73..94f89961de 100644
--- a/plugins/SmileyAdd/src/SmileyBase.cpp
+++ b/plugins/SmileyAdd/src/SmileyBase.cpp
@@ -156,7 +156,7 @@ ULONG ISmileyBase::AddRef(void)
 ULONG ISmileyBase::Release(void)
 {
 	LONG count = InterlockedDecrement(&m_lRefCount);
-	if(count == 0) 
+	if (count == 0) 
 		delete this;
 	return count;
 }
diff --git a/plugins/SmileyAdd/src/anim.cpp b/plugins/SmileyAdd/src/anim.cpp
index 0fbf663346..d84afa5bab 100644
--- a/plugins/SmileyAdd/src/anim.cpp
+++ b/plugins/SmileyAdd/src/anim.cpp
@@ -38,8 +38,7 @@ void Animate::StartAnimation(void)
 {
 	m_img = m_sml->CreateCachedImage();
 
-	if (m_img && m_img->IsAnimated())
-	{
+	if (m_img && m_img->IsAnimated()) {
 		m_img->SelectFrame(m_nFramePosition);
 		long frtm = m_img->GetFrameDelay();
 		m_counter = frtm / 10 + ((frtm % 10) >= 5);
@@ -49,8 +48,7 @@ void Animate::StartAnimation(void)
 
 void Animate::ProcessTimerTick(HWND hwnd)
 {
-	if (m_running && m_img->IsAnimated() && --m_counter <= 0)
-	{
+	if (m_running && m_img->IsAnimated() && --m_counter <= 0) {
 		m_nFramePosition = m_img->SelectNextFrame(m_nFramePosition);
 
 		long frtm = m_img->GetFrameDelay();
@@ -82,8 +80,7 @@ void Animate::DrawFrame(HDC hdc)
 
 void Animate::Draw(HDC hdc) 
 { 
-	if (m_running)
-	{
+	if (m_running) {
 		m_img->Draw(hdc, m_cliprect, m_clip);
 
 		if (m_sel)
@@ -102,16 +99,14 @@ void Animate::SetOffset(int off, int wsize)
 	m_offset = off; 
 
 	m_running = m_cliprect.top >= 0 && m_cliprect.top < wsize;
-	if (m_running)
-	{
-		if (m_img == NULL) 
-		{
+	if (m_running) {
+		if (m_img == NULL) {
 			StartAnimation();
-			if (m_img == NULL) m_running = false;
+			if (m_img == NULL)
+				m_running = false;
 		}
 	}
-	else
-	{
+	else {
 		if (m_img) m_img->Release();
 		m_img = NULL;
 	}
@@ -120,8 +115,7 @@ void Animate::SetOffset(int off, int wsize)
 
 void Animate::SetSel(int x, int y)
 {
-	m_sel = x >= m_cliprect.left && x < m_cliprect.right && 
-		y >= m_cliprect.top && y < m_cliprect.bottom;
+	m_sel = x >= m_cliprect.left && x < m_cliprect.right && y >= m_cliprect.top && y < m_cliprect.bottom;
 }
 
 
diff --git a/plugins/SmileyAdd/src/bkstring.cpp b/plugins/SmileyAdd/src/bkstring.cpp
deleted file mode 100644
index dc8d653e84..0000000000
--- a/plugins/SmileyAdd/src/bkstring.cpp
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
-Miranda SmileyAdd Plugin
-Copyright (C) 2008 - 2011 Boris Krasnovskiy All Rights Reserved
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation version 2
-of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "general.h"
-
-bkstring::~bkstring() { if (sizeAlloced) free(buf); }
-
-void bkstring::reserve(size_type len)
-{
-	if (len >= sizeAlloced || sizeAlloced == 0)
-	{
-		if (sizeAlloced == 0) buf = NULL;
-		buf = (value_type*)realloc(buf, (len+1) * sizeof(value_type));
-		if (sizeAlloced == 0) buf[0] = 0;
-		sizeAlloced = len+1;
-	}
-}
-
-void bkstring::appendfmt(const value_type *fmt, ...) 
-{
-	areserve(_tcslen(fmt)*2);
-
-	va_list vararg;
-	va_start(vararg, fmt);
-	for (;;) 
-	{
-		int len = mir_vsntprintf(buf + lenBuf, sizeAlloced - lenBuf - 1, fmt, vararg);
-		if (len < 0)
-			reserve(sizeAlloced + 256);
-		else
-		{
-			lenBuf += len;
-			buf[lenBuf] = 0;
-			break;
-		}
-	}
-	va_end(vararg);
-}
-
-bkstring& bkstring::append(const value_type* _Ptr)
-{
-	size_type len = _tcslen(_Ptr);
-	areserve(len);
-	memcpy(buf+lenBuf, _Ptr, (len+1)*sizeof(value_type));
-	lenBuf += len;
-	return *this;
-}
-
-bkstring& bkstring::append(const value_type* _Ptr, size_type _Count)
-{
-	size_type len = min(_tcslen(_Ptr), _Count);
-	areserve(len);
-	memcpy(buf+lenBuf, _Ptr, len*sizeof(value_type));
-	lenBuf += len;
-	buf[lenBuf] = 0;
-	return *this;
-}
-
-bkstring& bkstring::append(const bkstring& _Str, size_type _Off, size_type _Count)
-{
-	size_type len = min(_Count, _Str.size() - _Off);
-	areserve(len);
-	memcpy(buf+lenBuf, _Str.c_str()+_Off, len*sizeof(value_type));
-	lenBuf += len;
-	buf[lenBuf] = 0;
-	return *this;
-}
-
-bkstring& bkstring::append(const bkstring& _Str)
-{
-	size_type len = _Str.size();
-	areserve(len);
-	memcpy(buf+lenBuf, _Str.c_str(), len*sizeof(value_type));
-	lenBuf += len;
-	buf[lenBuf] = 0;
-	return *this;
-}
-
-bkstring& bkstring::append(size_type _Count, value_type _Ch)
-{
-	areserve(_Count);
-	for(size_type i=0; i<_Count; ++i) buf[lenBuf+i] = _Ch;
-	lenBuf += _Count;
-	buf[lenBuf] = 0;
-	return *this;
-}
-
-
-bkstring& bkstring::assign(const value_type* _Ptr, size_type _Count)
-{
-	if (_Count == 0 && sizeAlloced == 0)
-	{
-		buf = (TCHAR*)_T("");
-	}
-	else
-	{
-		reserve(_Count);
-		memcpy(buf, _Ptr, _Count*sizeof(value_type));
-		buf[_Count] = 0;
-		lenBuf = _Count;
-	}
-	return *this;
-}
-
-bkstring& bkstring::assign(const bkstring& _Str, size_type _Off, size_type _Count)
-{
-	size_type len = min(_Count, _Str.size() - _Off);
-	if (len == 0 && sizeAlloced == 0)
-	{
-		buf = (TCHAR*)_T("");
-	}
-	else
-	{
-		reserve(len);
-		memcpy(buf, _Str.c_str() + _Off, len*sizeof(value_type));
-		lenBuf = len;
-		buf[len] = 0;
-	}
-	return *this;
-}
-
-bkstring& bkstring::assign(size_type _Count, value_type _Ch)
-{
-	reserve(_Count);
-	for(size_type i=0; i<_Count; ++i) buf[i] = _Ch;
-	buf[_Count] = 0;
-	lenBuf = _Count;
-	return *this;
-}
-
-bkstring::size_type bkstring::find(value_type _Ch, size_type _Off) const
-{
-	for (size_type i=_Off; i<=lenBuf; ++i)
-		if (buf[i] == _Ch) return i;
-	return (size_type)npos;
-}
-
-bkstring::size_type bkstring::find(const value_type* _Ptr, size_type _Off) const
-{
-	if (_Off > lenBuf) return (size_type)npos;
-
-	value_type* pstr = _tcsstr(buf+_Off, _Ptr);
-	return pstr ? pstr - buf : npos;
-}
-
-bkstring::size_type bkstring::find_last_of(value_type _Ch, size_type _Off) const
-{
-	for (size_type i=(_Off == npos ? lenBuf : _Off); i--;)
-		if (buf[i] == _Ch) return i;
-	return (size_type)npos;
-}
-
-bkstring& bkstring::insert(size_type _P0, const value_type* _Ptr, size_type _Count)
-{
-	size_type len = _tcslen(_Ptr);
-	if (_Count < len) len = _Count;
-	areserve(len);
-	value_type *p = buf + _P0;
-	memmove(p+len, p, (lenBuf-_P0+1)*sizeof(value_type));
-	memcpy(p, _Ptr, _Count*sizeof(value_type));
-	lenBuf += len;
-	return *this;
-}
-
-bkstring& bkstring::insert(size_type _P0, size_type _Count, value_type _Ch)
-{
-	areserve(_Count);
-	value_type *p = buf + _P0;
-	memmove(p+_Count, p, (lenBuf-_P0+1)*sizeof(value_type));
-	for(size_type i=0; i<_Count; ++i) p[i] = _Ch;
-	lenBuf += _Count;
-	return *this;
-}
-
-bkstring& bkstring::erase(size_type _Pos, size_type _Count)
-{
-	if (_Pos < lenBuf)
-	{
-		const size_type len = min(lenBuf - _Pos, _Count);
-		value_type *p = buf + _Pos;
-		lenBuf -= len;
-		memmove(p, p+len, (lenBuf - _Pos)*sizeof(value_type));
-		buf[lenBuf] = 0;
-	}
-	return *this;
-}
diff --git a/plugins/SmileyAdd/src/bkstring.h b/plugins/SmileyAdd/src/bkstring.h
deleted file mode 100644
index f5752cb280..0000000000
--- a/plugins/SmileyAdd/src/bkstring.h
+++ /dev/null
@@ -1,258 +0,0 @@
-/*
-Miranda SmileyAdd Plugin
-Copyright (C) 2008 - 2011 Boris Krasnovskiy All Rights Reserved
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation version 2
-of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-
-class bkstring
-{
-public:
-	typedef size_t size_type;
-	typedef TCHAR  value_type;
-	typedef value_type* iterator;
-	typedef const value_type* const_iterator;
-
-	static const size_type npos = size_type(-1);
-
-private:
-	value_type* buf;
-	size_type sizeAlloced;
-	size_type lenBuf;
-
-	void areserve(size_type len) { reserve(lenBuf + len); }
-
-public:
-
-	explicit bkstring() : buf((TCHAR*)_T("")), sizeAlloced(0), lenBuf(0) 
-	{}
-
-	bkstring(const value_type* _Ptr, size_type _Count) : sizeAlloced(0), lenBuf(0)
-	{ assign(_Ptr, _Count); }
-
-	bkstring(const value_type* _Ptr) : sizeAlloced(0), lenBuf(0)
-	{ assign(_Ptr); }
-
-	bkstring(size_type _Count, value_type _Ch) : sizeAlloced(0), lenBuf(0)
-	{ assign(_Count, _Ch); }
-
-	bkstring(const bkstring& _Str) : sizeAlloced(0), lenBuf(0)
-	{ assign(_Str); }
-
-	bkstring(const bkstring& _Str, size_type _Off, size_type _Count) : sizeAlloced(0), lenBuf(0)
-	{ assign(_Str, _Off, _Count); }
-
-	~bkstring();
-
-	size_type size(void) const { return lenBuf; }
-	const value_type* c_str(void) const { return buf; }
-
-	void clear(void) { if (lenBuf) { lenBuf = 0; buf[0] = 0; } }
-	void insert(const value_type *txt);
-	void reserve(size_type len);
-
-	bkstring& assign(const value_type* _Ptr)
-	{ return assign(_Ptr, _tcslen(_Ptr)); }
-
-	bkstring& assign(const bkstring& _Str)
-	{ return assign(_Str, 0, (size_type)npos); }
-
-	bkstring& assign(const value_type* _Ptr, size_type _Count);
-	bkstring& assign(const bkstring& _Str, size_type off, size_type _Count);
-	bkstring& assign(size_type _Count, value_type _Ch);
-
-	bkstring& append(const value_type* _Ptr);
-	bkstring& append(const value_type* _Ptr, size_type _Count);
-	bkstring& append(const bkstring& _Str, size_type _Off, size_type _Count);
-	bkstring& append(const bkstring& _Str);
-	bkstring& append(size_type _Count, value_type _Ch);
-
-	int compare(const bkstring& _Str) const 
-	{ return _tcscmp(buf, _Str.c_str()); }
-	
-	int compare(size_type _Pos1, size_type _Num1, const bkstring& _Str) const 
-	{ return _tcsncmp(&buf[_Pos1], _Str.c_str(), _Num1); }
-	
-	int compare(size_type _Pos1, size_type _Num1, const bkstring& _Str, size_type _Off, size_type _Count) const
-	{ return _tcsncmp(&buf[_Pos1], _Str.c_str()+_Off, min(_Num1, _Count)); }
-
-	int compare(const value_type* _Ptr) const 
-	{ return _tcscmp(buf, _Ptr); }
-	
-	int compare(size_type _Pos1, size_type _Num1, const value_type* _Ptr) const
-	{ return _tcsncmp(&buf[_Pos1], _Ptr, _Num1); }
-	
-	int compare(size_type _Pos1, size_type _Num1, const value_type* _Ptr, size_type _Num2) const
-	{ return _tcsncmp(&buf[_Pos1], _Ptr, min(_Num1, _Num2)); }
-
-	int comparei(const bkstring& _Str) const 
-	{ return _tcsicmp(buf, _Str.c_str()); }
-	
-	int comparei(size_type _Pos1, size_type _Num1, const bkstring& _Str) const 
-	{ return _tcsnicmp(&buf[_Pos1], _Str.c_str(), _Num1); }
-	
-	int comparei(size_type _Pos1, size_type _Num1, const bkstring& _Str, size_type _Off, size_type _Count) const
-	{ return _tcsnicmp(&buf[_Pos1], _Str.c_str()+_Off, min(_Num1, _Count)); }
-
-	int comparei(const value_type* _Ptr) const 
-	{ return _tcsicmp(buf, _Ptr); }
-	
-	int comparei(size_type _Pos1, size_type _Num1, const value_type* _Ptr) const
-	{ return _tcsnicmp(&buf[_Pos1], _Ptr, _Num1); }
-	
-	int comparei(size_type _Pos1, size_type _Num1, const value_type* _Ptr, size_type _Num2) const
-	{ return _tcsnicmp(&buf[_Pos1], _Ptr, min(_Num1, _Num2)); }
-
-	bool empty(void) const { return lenBuf == 0; };
-	bkstring& erase(size_type _Pos = 0, size_type _Count = npos);
-
-	size_type find(value_type _Ch, size_type _Off = 0) const;
-	size_type find(const value_type* _Ptr, size_type _Off = 0) const;
-	size_type find(bkstring& _Str, size_type _Off = 0) const
-	{ return find(_Str.c_str(), _Off); }
-
-	size_type find_last_of(value_type _Ch, size_type _Off = npos) const;
-
-	bkstring& insert(size_type _P0, const value_type* _Ptr)
-	{ return insert(_P0, _Ptr, _tcslen(_Ptr)); }
-	
-	bkstring& insert(size_type _P0, const bkstring& _Str)
-	{ return insert(_P0, _Str.c_str(), _Str.size()); };
-
-	bkstring& insert(size_type _P0, const value_type* _Ptr, size_type _Count);
-	bkstring& insert(size_type _P0, size_type _Count, value_type _Ch);
-
-	bkstring substr(size_type _Off = 0, size_type _Count = npos) const
-	{ return bkstring(*this, _Off, _Count); }
-
-	bkstring& operator = (const bkstring& _Str)
-	{ return assign(_Str); }
-
-	bkstring& operator =(const value_type* _Ptr)
-	{ return assign(_Ptr); }
-
-	bkstring& operator = (const value_type _Ch)
-	{ return assign(1, _Ch); }
-
-	bkstring& operator +=(const bkstring& _Str)
-	{ return append(_Str); }
-
-	bkstring& operator += (const value_type* _Ptr)
-	{ return append(_Ptr); }
-
-	bkstring& operator += (const value_type _Ch)
-	{ return append(1, _Ch); }
-
-	value_type& operator[] (size_t ind) const
-	{ return buf[ind]; }
-
-	friend bkstring operator+ (const bkstring& _Str1, const bkstring& _Str2)
-	{ bkstring s(_Str1); return s.append(_Str2); }
-
-	friend bkstring operator+ (const bkstring& _Str1, const value_type* _Ptr2)
-	{ bkstring s(_Str1); return s.append(_Ptr2); }
-
-	friend bkstring operator+(const value_type* _Ptr1, const bkstring& _Str2)
-	{ bkstring s(_Ptr1); return s.append(_Str2); }
-
-	friend bkstring operator+ (const bkstring& _Str1, const value_type _Ch)
-	{ bkstring s(_Str1); return s.append(1, _Ch); }
-
-	friend bool operator==(const bkstring& _Str1, const bkstring& _Str2)
-	{ return _Str1.compare(_Str2) == 0; }
-
-	friend bool operator==(const bkstring& _Str1, const value_type* _Ptr2)
-	{ return _Str1.compare(_Ptr2) == 0; }
-
-	friend bool operator==(const value_type* _Ptr1, const bkstring& _Str2)
-	{ return _Str2.compare(_Ptr1) == 0; }
-
-	friend bool operator!=(const bkstring& _Str1, const bkstring& _Str2)
-	{ return _Str1.compare(_Str2) != 0; }
-
-	friend bool operator!=(const bkstring& _Str1, const value_type* _Ptr2)
-	{ return _Str1.compare(_Ptr2) != 0; }
-
-	friend bool operator!=(const value_type* _Ptr1, const bkstring& _Str2)
-	{ return _Str2.compare(_Ptr1) != 0; }
-
-	friend bool operator<(const bkstring& _Str1, const bkstring& _Str2)
-	{ return _Str1.compare(_Str2) < 0; }
-
-	friend bool operator<(const bkstring& _Str1, const value_type* _Ptr2)
-	{ return _Str1.compare(_Ptr2) < 0; }
-
-	friend bool operator<(const value_type* _Ptr1, const bkstring& _Str2)
-	{ return _Str2.compare(_Ptr1) > 0; }
-
-	friend bool operator>(const bkstring& _Str1, const bkstring& _Str2)
-	{ return _Str1.compare(_Str2) > 0; }
-
-	friend bool operator>(const bkstring& _Str1, const value_type* _Ptr2)
-	{ return _Str1.compare(_Ptr2) > 0; }
-
-	friend bool operator>(const value_type* _Ptr1, const bkstring& _Str2)
-	{ return _Str2.compare(_Ptr1) < 0; }
-
-	friend bool operator<=(const bkstring& _Str1, const bkstring& _Str2)
-	{ return _Str1.compare(_Str2) <= 0; }
-
-	friend bool operator<=(const bkstring& _Str1, const value_type* _Ptr2)
-	{  return _Str1.compare(_Ptr2) <= 0; }
-
-	friend bool  operator<=(const value_type* _Ptr1, const bkstring& _Str2)
-	{ return _Str2.compare(_Ptr1) >= 0; }
-
-	friend bool  operator>=(const bkstring& _Str1, const bkstring& _Str2)
-	{ return _Str1.compare(_Str2) >= 0; }
-
-	friend bool  operator>=(const bkstring& _Str1, const value_type* _Ptr2)
-	{ return _Str1.compare(_Ptr2) >= 0; }
-
-	friend bool  operator>=(const value_type* _Ptr1, const bkstring& _Str2)
-	{ return _Str2.compare(_Ptr1) <= 0; }
-
-	friend bool  operator==(const value_type _Ch1, const bkstring& _Str2)
-	{  return (_Str2.size() == 1) && (_Str2[0] == _Ch1); }
-
-	friend bool  operator==(const bkstring& _Str1, const value_type _Ch2)
-	{ return (_Str1.size() == 1) && (_Str1[0] == _Ch2); }
-
-	friend bool  operator!=(const value_type _Ch1, const bkstring& _Str2)
-	{  return (_Str2.size() != 1) || (_Str2[0] != _Ch1); }
-
-	friend bool  operator!=(const bkstring& _Str1, const value_type _Ch2)
-	{ return (_Str1.size() != 1) || (_Str1[0] != _Ch2); }
-
-	iterator begin(void)
-	{ return buf; }
-	
-	const_iterator begin(void) const
-	{ return buf; }
-	
-	iterator end(void)
-	{ return buf + lenBuf; }
-
-	const_iterator end(void) const
-	{ return buf + lenBuf; }
-	  
-	// Custom extentions
-
-	void appendfmt(const value_type *fmt, ...);
-
-	size_type sizebytes(void) const { return lenBuf * sizeof(value_type); }
-};
-
-//const bkstring::size_type bkstring::npos = -1;
diff --git a/plugins/SmileyAdd/src/customsmiley.cpp b/plugins/SmileyAdd/src/customsmiley.cpp
index a41920d140..8dd946429d 100644
--- a/plugins/SmileyAdd/src/customsmiley.cpp
+++ b/plugins/SmileyAdd/src/customsmiley.cpp
@@ -64,7 +64,7 @@ SmileyPackCType* SmileyPackCListType::GetSmileyPack(HANDLE id)
 }
 
 
-SmileyCType::SmileyCType(const bkstring& fullpath, const TCHAR* filepath)
+SmileyCType::SmileyCType(const CMString& fullpath, const TCHAR* filepath)
 {
 	LoadFromResource(fullpath, 0); 
 	CreateTriggerText(T2A_SM(filepath));
@@ -101,7 +101,7 @@ bool SmileyCType::CreateTriggerText(char* text)
 
 bool SmileyPackCType::LoadSmileyDir(TCHAR* dir)
 {
-	bkstring dirs = dir;
+	CMString dirs = dir;
 	dirs += _T("\\*.*");
 
 	_tfinddata_t c_file;
@@ -111,14 +111,14 @@ bool SmileyPackCType::LoadSmileyDir(TCHAR* dir)
 		do {
 			if (c_file.name[0] != '.')
 			{
-				bkstring fullpath = dir;
+				CMString fullpath = dir;
 				fullpath = fullpath + _T("\\") + c_file.name;
 				TCHAR* div = _tcsrchr(c_file.name, '.');
 				if (div)
 				{
 					*div = 0;
 					SmileyCType *smlc = new SmileyCType(fullpath, c_file.name);
-					if (smlc->GetTriggerText().empty())
+					if (smlc->GetTriggerText().IsEmpty())
 						delete smlc;
 					else
 						m_SmileyList.insert(smlc);
@@ -135,11 +135,11 @@ bool SmileyPackCType::LoadSmileyDir(TCHAR* dir)
 
 bool SmileyPackCType::LoadSmiley(TCHAR* path)
 {
-	bkstring dirs = path;
-	bkstring::size_type slash = dirs.find_last_of('\\');
-	bkstring::size_type dot = dirs.find_last_of('.');
+	CMString dirs = path;
+	int slash = dirs.ReverseFind('\\');
+	int dot = dirs.ReverseFind('.');
 
-	bkstring name = dirs.substr(slash+1, dot - slash - 1); 
+	CMString name = dirs.Mid(slash+1, dot - slash - 1); 
 
 	for (int i=0; i < m_SmileyList.getCount(); i++) {
 		if (m_SmileyList[i].GetTriggerText() == name) {
@@ -150,7 +150,7 @@ bool SmileyPackCType::LoadSmiley(TCHAR* path)
 
 	m_SmileyList.insert(new SmileyCType(dirs, (TCHAR*)name.c_str()));
 
-	bkstring empty;
+	CMString empty;
 	m_SmileyLookup.insert(new SmileyLookup(
 		m_SmileyList[m_SmileyList.getCount()-1].GetTriggerText(), false, m_SmileyList.getCount()-1, empty));
 
@@ -160,7 +160,7 @@ bool SmileyPackCType::LoadSmiley(TCHAR* path)
 
 void SmileyPackCType::AddTriggersToSmileyLookup(void)
 {
-	bkstring empty;
+	CMString empty;
 	for (int dist=0; dist<m_SmileyList.getCount(); dist++) {
 		SmileyLookup *dats = new SmileyLookup(m_SmileyList[dist].GetTriggerText(), false, dist, empty); 
 		m_SmileyLookup.insert(dats);
diff --git a/plugins/SmileyAdd/src/customsmiley.h b/plugins/SmileyAdd/src/customsmiley.h
index 594595977a..c613b5dc75 100644
--- a/plugins/SmileyAdd/src/customsmiley.h
+++ b/plugins/SmileyAdd/src/customsmiley.h
@@ -22,7 +22,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 class SmileyCType : public SmileyType
 {
 public:
-	SmileyCType(const bkstring& fullpath, const TCHAR* filepath);
+	SmileyCType(const CMString& fullpath, const TCHAR* filepath);
 
 	bool CreateTriggerText(char* text);
 };
@@ -39,7 +39,7 @@ private:
 
 	HANDLE m_id;
 
-	void InsertLookup(SmileyCType& sml, bkstring& lk, bool first);
+	void InsertLookup(SmileyCType& sml, CMString& lk, bool first);
 	void AddTriggersToSmileyLookup(void);
 
 public:
diff --git a/plugins/SmileyAdd/src/download.cpp b/plugins/SmileyAdd/src/download.cpp
index fcb4a06139..c3a68a11d3 100644
--- a/plugins/SmileyAdd/src/download.cpp
+++ b/plugins/SmileyAdd/src/download.cpp
@@ -23,11 +23,11 @@ static HANDLE hFolder;
 
 struct QueueElem
 {
-	bkstring url;
-	bkstring fname;
+	CMString url;
+	CMString fname;
 	bool needext;
 
-	QueueElem(bkstring& purl, bkstring& pfname, bool ne)
+	QueueElem(CMString& purl, CMString& pfname, bool ne)
 		: url(purl), fname(pfname), needext(ne) {}
 };
 
@@ -58,26 +58,22 @@ bool InternetDownloadFile(const char *szUrl, char* szDest, HANDLE &hHttpDwnl)
 	nlhr.headers[1].szName  = "Connection";
 	nlhr.headers[1].szValue = "close";
 
-	while (result == 0xBADBAD)
-	{
+	while (result == 0xBADBAD) {
 		// download the page
 		NETLIBHTTPREQUEST *nlhrReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION,
 			(WPARAM)hNetlibUser,(LPARAM)&nlhr);
 
-		if (nlhrReply)
-		{
+		if (nlhrReply) {
 			hHttpDwnl = nlhrReply->nlc;
 			// if the recieved code is 200 OK
-			if(nlhrReply->resultCode == 200)
-			{
-				char* delim = strrchr(szDest, '\\');
+			if (nlhrReply->resultCode == 200) {
+				char *delim = strrchr(szDest, '\\');
 				if (delim) *delim = '\0';
 				CreateDirectoryTree(szDest);
 				if (delim) *delim = '\\';
 				int res = -1;
 				int fh = _open(szDest, _O_BINARY | _O_WRONLY | _O_CREAT, _S_IREAD | _S_IWRITE);
-				if (fh != -1)
-				{
+				if (fh != -1) {
 					res = _write(fh, nlhrReply->pData, nlhrReply->dataLength);
 					_close(fh);
 				}
@@ -88,17 +84,13 @@ bool InternetDownloadFile(const char *szUrl, char* szDest, HANDLE &hHttpDwnl)
 			}
 			// if the recieved code is 302 Moved, Found, etc
 			// workaround for url forwarding
-			else if(nlhrReply->resultCode == 302 || nlhrReply->resultCode == 301 || nlhrReply->resultCode == 307) // page moved
-			{
+			else if (nlhrReply->resultCode == 302 || nlhrReply->resultCode == 301 || nlhrReply->resultCode == 307) { // page moved
 				// get the url for the new location and save it to szInfo
 				// look for the reply header "Location"
-				for (int i=0; i<nlhrReply->headersCount; i++)
-				{
-					if (!strcmp(nlhrReply->headers[i].szName, "Location"))
-					{
+				for (int i=0; i<nlhrReply->headersCount; i++) {
+					if (!strcmp(nlhrReply->headers[i].szName, "Location")) {
 						size_t rlen = 0;
-						if (nlhrReply->headers[i].szValue[0] == '/')
-						{
+						if (nlhrReply->headers[i].szValue[0] == '/') {
 							const char* szPath;
 							const char* szPref = strstr(szUrl, "://");
 							szPref = szPref ? szPref + 3 : szUrl;
@@ -106,8 +98,7 @@ bool InternetDownloadFile(const char *szUrl, char* szDest, HANDLE &hHttpDwnl)
 							rlen = szPath != NULL ? szPath - szUrl : strlen(szUrl);
 						}
 
-						szRedirUrl = (char*)mir_realloc(szRedirUrl,
-							rlen + strlen(nlhrReply->headers[i].szValue)*3 + 1);
+						szRedirUrl = (char*)mir_realloc(szRedirUrl, rlen + strlen(nlhrReply->headers[i].szValue)*3 + 1);
 
 						strncpy(szRedirUrl, szUrl, rlen);
 						strcpy(szRedirUrl+rlen, nlhrReply->headers[i].szValue);
@@ -117,11 +108,9 @@ bool InternetDownloadFile(const char *szUrl, char* szDest, HANDLE &hHttpDwnl)
 					}
 				}
 			}
-			else
-				result = 1;
+			else result = 1;
 		}
-		else
-		{
+		else {
 			hHttpDwnl = NULL;
 			result = 1;
 		}
@@ -146,7 +135,7 @@ void __cdecl SmileyDownloadThread(void*)
 			InternetDownloadFile(T2A_SM(dlQueue[0].url.c_str()), T2A_SM(dlQueue[0].fname.c_str()), hHttpDwnl);
 			WaitForSingleObject(g_hDlMutex, 3000);
 
-			bkstring fname(dlQueue[0].fname);
+			CMString fname(dlQueue[0].fname);
 			if (dlQueue[0].needext) { fname += GetImageExt(fname); needext = true; }
 			_trename(dlQueue[0].fname.c_str(), fname.c_str());
 		}
@@ -159,8 +148,7 @@ void __cdecl SmileyDownloadThread(void*)
 	threadRunning = false;
 	ReleaseMutex(g_hDlMutex);
 
-	if (!Miranda_Terminated())
-	{
+	if (!Miranda_Terminated()) {
 		if (needext)
 			CallServiceSync(MS_SMILEYADD_RELOAD, 0, 0);
 		else
@@ -168,42 +156,42 @@ void __cdecl SmileyDownloadThread(void*)
 	}
 }
 
-bool GetSmileyFile(bkstring& url, const bkstring& packstr)
+bool GetSmileyFile(CMString& url, const CMString& packstr)
 {
-	_TPattern * urlsplit = _TPattern::compile(_T(".*/(.*)"));
-	_TMatcher * m0 = urlsplit->createTMatcher(url);
+	_TPattern *urlsplit = _TPattern::compile(_T(".*/(.*)"));
+	_TMatcher *m0 = urlsplit->createTMatcher(url);
 
 	m0->findFirstMatch();
 
-	bkstring filename;
-	filename.appendfmt(_T("%s\\%s\\"), cachepath, packstr.c_str());
-	size_t pathpos = filename.size();
+	CMString filename;
+	filename.AppendFormat(_T("%s\\%s\\"), cachepath, packstr.c_str());
+	int pathpos = filename.GetLength();
 	filename += m0->getGroup(1);
 
 	delete m0;
 	delete urlsplit;
 
-	bool needext = filename.find('.') == filename.npos;
-	if (needext) filename += _T(".*");
+	bool needext = filename.Find('.') == -1;
+	if (needext)
+		filename += _T(".*");
 
 	_tfinddata_t c_file;
 	INT_PTR hFile = _tfindfirst((TCHAR*)filename.c_str(), &c_file);
-	if (hFile > -1)
-	{
+	if (hFile > -1) {
 		_findclose(hFile);
-		filename.erase(pathpos);
+		filename.Truncate(pathpos);
 		filename += c_file.name;
 		url = filename;
 		return false;
 	}
-	if (needext) filename.erase(filename.size()-1);
+	if (needext)
+		filename.Truncate(filename.GetLength() - 1);
 
 	WaitForSingleObject(g_hDlMutex, 3000);
 	dlQueue.insert(new QueueElem(url, filename, needext));
 	ReleaseMutex(g_hDlMutex);
 
-	if (!threadRunning)
-	{
+	if (!threadRunning) {
 		threadRunning = true;
 		mir_forkthread(SmileyDownloadThread, NULL);
 	}
@@ -225,19 +213,13 @@ void GetSmileyCacheFolder(void)
 		FoldersGetCustomPathT(hFolder, cachepath, MAX_PATH, _T(""));
 		HookEvent(ME_FOLDERS_PATH_CHANGED, FolderChanged);
 	}
-	else
-	{
-		TCHAR* tszFolder = Utils_ReplaceVarsT(_T("%miranda_userdata%\\SmileyCache"));
-		lstrcpyn(cachepath, tszFolder, MAX_PATH);
-		mir_free(tszFolder);
-	}
+	else lstrcpyn(cachepath, VARST( _T("%miranda_userdata%\\SmileyCache")), MAX_PATH);
 }
 
 void DownloadInit(void)
 {
-	NETLIBUSER nlu = {0};
-	nlu.cbSize = sizeof(nlu);
-	nlu.flags = NUF_OUTGOING|NUF_HTTPCONNS|NUF_NOHTTPSOPTION|NUF_TCHAR;
+	NETLIBUSER nlu = { sizeof(nlu) };
+	nlu.flags = NUF_OUTGOING | NUF_HTTPCONNS | NUF_NOHTTPSOPTION | NUF_TCHAR;
 	nlu.szSettingsModule = "SmileyAdd";
 	nlu.ptszDescriptiveName = TranslateT("SmileyAdd HTTP connections");
 	hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
diff --git a/plugins/SmileyAdd/src/download.h b/plugins/SmileyAdd/src/download.h
index 977a98ef96..8bc7daec85 100644
--- a/plugins/SmileyAdd/src/download.h
+++ b/plugins/SmileyAdd/src/download.h
@@ -19,7 +19,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #ifndef SMILEYADD_DOWNLOAD_H_
 #define SMILEYADD_DOWNLOAD_H_
 
-bool GetSmileyFile(bkstring& url, const bkstring& packstr);
+bool GetSmileyFile(CMString& url, const CMString& packstr);
 void DownloadInit(void);
 void DownloadClose(void);
 
diff --git a/plugins/SmileyAdd/src/general.cpp b/plugins/SmileyAdd/src/general.cpp
index 0fa8cc9612..2d736ae9e8 100644
--- a/plugins/SmileyAdd/src/general.cpp
+++ b/plugins/SmileyAdd/src/general.cpp
@@ -68,7 +68,7 @@ HICON GetDefaultIcon(bool copy)
 }
 
 
-const TCHAR* GetImageExt(bkstring &fname)
+const TCHAR* GetImageExt(CMString &fname)
 {
 	const TCHAR* ext = _T("");
 
@@ -139,14 +139,14 @@ HICON ImageList_GetIconFixed (HIMAGELIST himl, INT i, UINT fStyle)
 	return hIcon;
 }
 
-void pathToRelative(const bkstring& pSrc, bkstring& pOut)
+void pathToRelative(const CMString& pSrc, CMString& pOut)
 {
 	TCHAR szOutPath[MAX_PATH];
 	PathToRelativeT(pSrc.c_str(), szOutPath);
 	pOut = szOutPath;
 }
 
-void pathToAbsolute(const bkstring& pSrc, bkstring& pOut) 
+void pathToAbsolute(const CMString& pSrc, CMString& pOut) 
 {
 	TCHAR szOutPath[MAX_PATH];
 
diff --git a/plugins/SmileyAdd/src/general.h b/plugins/SmileyAdd/src/general.h
index cb268cdfc7..302d898f18 100644
--- a/plugins/SmileyAdd/src/general.h
+++ b/plugins/SmileyAdd/src/general.h
@@ -60,13 +60,13 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <m_icolib.h>
 #include <m_genmenu.h>
 #include <m_imgsrvc.h>
+#include <m_string.h>
 
 #include <m_metacontacts.h>
 #include <m_smileyadd.h>
 #include <m_smileyadd_deprecated.h>
 #include <m_folders.h>
 
-#include "bkstring.h"
 #include "regexp\wcpattern.h"
 #include "regexp\wcmatcher.h"
 
@@ -171,15 +171,15 @@ bool IsOldSrmm(void);
 
 //functions for general use (defined in general.cpp)
 int CalculateTextHeight(HDC hdc, CHARFORMAT2* chf);
-const TCHAR* GetImageExt(bkstring &fname);
+const TCHAR* GetImageExt(CMString &fname);
 
 HANDLE DecodeMetaContact(HANDLE hContact);
 bool IsSmileyProto(char* proto);
 
 HICON ImageList_GetIconFixed (HIMAGELIST himl, INT i, UINT fStyle);
 
-void pathToRelative(const bkstring& pSrc, bkstring& pOut);
-void pathToAbsolute(const bkstring& pSrc, bkstring& pOut);
+void pathToRelative(const CMString& pSrc, CMString& pOut);
+void pathToAbsolute(const CMString& pSrc, CMString& pOut);
 
 bool InitGdiPlus(void);
 void DestroyGdiPlus(void);
diff --git a/plugins/SmileyAdd/src/imagecache.cpp b/plugins/SmileyAdd/src/imagecache.cpp
index 9d6fff549c..87b95f5a60 100644
--- a/plugins/SmileyAdd/src/imagecache.cpp
+++ b/plugins/SmileyAdd/src/imagecache.cpp
@@ -23,7 +23,7 @@ static FI_INTERFACE *fei;
 static HANDLE g_hMutexIm;
 static OBJLIST<ImageBase> g_imagecache(25, ImageType::CompareImg);
 
-static bkstring lastdllname;
+static CMString lastdllname;
 static HMODULE lastmodule;
 static time_t laststamp;
 static UINT_PTR timerId;
@@ -36,7 +36,7 @@ static void CALLBACK timerProc(HWND, UINT, UINT_PTR, DWORD)
 	{
 		FreeLibrary(lastmodule);
 		lastmodule = NULL;
-		lastdllname.clear();
+		lastdllname.Empty();
 	}
 
 	for (int i=g_imagecache.getCount()-1; i >= 0; i--)
@@ -61,7 +61,7 @@ static void CALLBACK sttMainThreadCallback( PVOID )
 }
 
 
-static HMODULE LoadDll(const bkstring& file)
+static HMODULE LoadDll(const CMString& file)
 {
 	WaitForSingleObject(g_hMutexIm, 3000);
 
@@ -198,7 +198,7 @@ int ImageBase::SelectNextFrame(const int frame)
 
 
 
-IconType::IconType(const unsigned id, const bkstring& file, const int index, const IcoTypeEnum type)
+IconType::IconType(const unsigned id, const CMString& file, const int index, const IcoTypeEnum type)
 	: ImageBase(id)
 {
 	m_SmileyIcon = NULL;
@@ -288,7 +288,7 @@ void ImageListItemType::GetSize(SIZE& size)
 	ImageList_GetIconSize(m_hImList, (int*)&size.cx, (int*)&size.cy);
 }
 
-ImageType::ImageType(const unsigned id, const bkstring& file, IStream* pStream)
+ImageType::ImageType(const unsigned id, const CMString& file, IStream* pStream)
 	: ImageBase(id)
 {
 	m_bmp           = NULL;
@@ -321,7 +321,7 @@ ImageType::ImageType(const unsigned id, const bkstring& file, IStream* pStream)
 	}
 }
 
-ImageType::ImageType(const unsigned id, const bkstring& file, const int index, const IcoTypeEnum type)
+ImageType::ImageType(const unsigned id, const CMString& file, const int index, const IcoTypeEnum type)
 	: ImageBase(id)
 {
 	m_bmp           = NULL;
@@ -437,7 +437,7 @@ ImageFType::ImageFType(const unsigned id)
 	m_bmp = NULL;
 }
 
-ImageFType::ImageFType(const unsigned id, const bkstring& file)
+ImageFType::ImageFType(const unsigned id, const CMString& file)
 	: ImageBase(id)
 {
 	m_bmp = NULL;
@@ -589,7 +589,7 @@ void ImageFType::GetSize(SIZE& size)
 	}
 }
 /*
-ImageFAniType::ImageFAniType(const unsigned id, const bkstring& file)
+ImageFAniType::ImageFAniType(const unsigned id, const CMString& file)
 : ImageFType(id)
 {
 	m_fmbmp = NULL;
@@ -720,10 +720,10 @@ void DestroyImageCache(void)
 }
 
 
-ImageBase* AddCacheImage(const bkstring& file, int index)
+ImageBase* AddCacheImage(const CMString& file, int index)
 {
-	bkstring tmpfile(file); tmpfile.appendfmt(_T("#%d"), index);
-	unsigned id = hash(tmpfile.c_str(), (unsigned int)tmpfile.size() * sizeof(TCHAR));
+	CMString tmpfile(file); tmpfile.AppendFormat(_T("#%d"), index);
+	unsigned id = hash(tmpfile.c_str(), (unsigned int)tmpfile.GetLength() * sizeof(TCHAR));
 
 	WaitForSingleObject(g_hMutexIm, 3000);
 
@@ -731,19 +731,21 @@ ImageBase* AddCacheImage(const bkstring& file, int index)
 	ImageBase *img = g_imagecache.find(&srch);
 	if (img == NULL)
 	{
-		bkstring::size_type ind = file.find_last_of('.');
-		if (ind == file.npos) return NULL;
-		bkstring ext = file.substr(ind+1);
+		int ind = file.ReverseFind('.');
+		if (ind == -1)
+			return NULL;
 
-		if (ext.comparei(_T("dll")) == 0 || ext.comparei(_T("exe")) == 0)
+		CMString ext = file.Right(ind+1);
+		ext.MakeLower();
+		if (ext == _T("dll") || ext == _T("exe"))
 			img = opt.HQScaling ? (ImageBase*)new ImageType(id, file, index, icoDll) : (ImageBase*)new IconType(id, file, index, icoDll);
-		else if (ext.comparei(_T("ico")) == 0)
+		else if (ext == _T("ico"))
 			img = opt.HQScaling ? (ImageBase*)new ImageType(id, file, 0, icoFile) : (ImageBase*)new IconType(id, file, 0, icoFile);
-		else if (ext.comparei(_T("icl")) == 0)
+		else if (ext == _T("icl"))
 			img = opt.HQScaling ? (ImageBase*)new ImageType(id, file, index, icoIcl) : (ImageBase*)new IconType(id, file, index, icoIcl);
-		else if (ext.comparei(_T("gif")) == 0)
+		else if (ext == _T("gif"))
 			img = new ImageType(id, file, NULL);
-		else if (fei == NULL || ext.comparei(_T("tif")) == 0 || ext.comparei(_T("tiff")) == 0)
+		else if (fei == NULL || ext == _T("tif") || ext == _T("tiff"))
 			img = new ImageType(id, file, NULL);
 		else
 			img = opt.HQScaling ? (ImageBase*)new ImageType(id, file, NULL) : (ImageBase*)new ImageFType(id, file);
diff --git a/plugins/SmileyAdd/src/imagecache.h b/plugins/SmileyAdd/src/imagecache.h
index 87e04bafd0..d8abe2e6b6 100644
--- a/plugins/SmileyAdd/src/imagecache.h
+++ b/plugins/SmileyAdd/src/imagecache.h
@@ -66,7 +66,7 @@ private:
 	HICON m_SmileyIcon;
 
 public:
-	IconType(const unsigned id, const bkstring& file, const int index, const IcoTypeEnum type);
+	IconType(const unsigned id, const CMString& file, const int index, const IcoTypeEnum type);
 	~IconType();
 
 	void DrawInternal(HDC dc, int x, int y, int sizeX, int sizeY);
@@ -101,8 +101,8 @@ private:
 
 public:
 
-	ImageType(const unsigned id, const bkstring& file, IStream* pStream);
-    ImageType(const unsigned id, const bkstring& file, const int index, const IcoTypeEnum type);
+	ImageType(const unsigned id, const CMString& file, IStream* pStream);
+    ImageType(const unsigned id, const CMString& file, const int index, const IcoTypeEnum type);
 	~ImageType();
 
     void SelectFrame(int frame);
@@ -123,7 +123,7 @@ protected:
 public:
 
     ImageFType(const unsigned id);
-	ImageFType(const unsigned id, const bkstring& file);
+	ImageFType(const unsigned id, const CMString& file);
 	~ImageFType();
 
 	void DrawInternal(HDC dc, int x, int y, int sizeX, int sizeY);
@@ -143,7 +143,7 @@ private:
 
 public:
 
-	ImageFAniType(const unsigned id, const bkstring& file);
+	ImageFAniType(const unsigned id, const CMString& file);
 	~ImageFAniType();
 
     void SelectFrame(int frame);
@@ -154,7 +154,7 @@ public:
 */
 
 
-ImageBase* AddCacheImage(const bkstring& file, int index);
+ImageBase* AddCacheImage(const CMString& file, int index);
 
 void InitImageCache(void);
 void DestroyImageCache(void);
diff --git a/plugins/SmileyAdd/src/options.cpp b/plugins/SmileyAdd/src/options.cpp
index 62e1668848..90daa34791 100644
--- a/plugins/SmileyAdd/src/options.cpp
+++ b/plugins/SmileyAdd/src/options.cpp
@@ -265,10 +265,9 @@ void OptionsDialogType::AddCategory(void)
 	TCHAR cat[30];
 
 	GetDlgItemText(m_hwndDialog, IDC_NEWCATEGORY, cat, SIZEOF(cat)); 
-	bkstring catd = cat;
+	CMString catd = cat;
 
-	if (!catd.empty())
-	{
+	if (!catd.IsEmpty()) {
 		tmpsmcat.AddCategory(cat, catd, smcCustom);
 
 		PopulateSmPackList();
@@ -281,17 +280,11 @@ void OptionsDialogType::UserAction(HTREEITEM hItem)
 {
 	HWND hLstView = GetDlgItem(m_hwndDialog, IDC_CATEGORYLIST);
 
-	if (TreeView_GetCheckState(hLstView, hItem))
-	{
+	if (TreeView_GetCheckState(hLstView, hItem)) {
 		if (!BrowseForSmileyPacks(GetSelProto(hItem)))
-		{
 			TreeView_SetCheckState(hLstView, hItem, TRUE)
-		}
-	}
-	else
-	{
-		tmpsmcat.GetSmileyCategory(GetSelProto(hItem))->ClearFilename();
 	}
+	else tmpsmcat.GetSmileyCategory(GetSelProto(hItem))->ClearFilename();
 
 	if (hItem == TreeView_GetSelection(hLstView))
 		UpdateControls();
@@ -313,14 +306,12 @@ void OptionsDialogType::UpdateControls(bool force)
 	const SmileyCategoryType* smc = tmpsmcat.GetSmileyCategory(GetSelProto());
 	if (smc == NULL) return;
 
-	const bkstring& smf = smc->GetFilename();
+	const CMString& smf = smc->GetFilename();
 
 	SetDlgItemText(m_hwndDialog, IDC_FILENAME, smf.c_str());
 
 	if (smPack.GetFilename() != smf || force)
-	{
 		smPack.LoadSmileyFile(smf, false, true);
-	}
 
 	HWND hLstView = GetDlgItem(m_hwndDialog, IDC_CATEGORYLIST);
 	TreeView_SetCheckState(hLstView, TreeView_GetSelection(hLstView), smPack.SmileyCount() != 0);
@@ -485,7 +476,7 @@ void OptionsDialogType::ApplyChanges(void)
 	SmileyCategoryListType::SmileyCategoryVectorType& smc = *g_SmileyCategories.GetSmileyCategoryList();
 	for (int i=0; i < smc.getCount(); i++) {
 		if (tmpsmcat.GetSmileyCategory(smc[i].GetName()) == NULL) {
-			bkstring empty;
+			CMString empty;
 			opt.WritePackFileName(empty, smc[i].GetName());
 		}
 	}
@@ -508,13 +499,13 @@ bool OptionsDialogType::BrowseForSmileyPacks(int item)
 	ofn.lpstrFile = filename;
 	ofn.nMaxFile = SIZEOF(filename);
 
-	bkstring inidir;
+	CMString inidir;
 	SmileyCategoryType* smc = tmpsmcat.GetSmileyCategory(item); 
-	if (smc->GetFilename().empty())
+	if (smc->GetFilename().IsEmpty())
 		pathToAbsolute(_T("Smileys"), inidir);
 	else {
 		pathToAbsolute(smc->GetFilename(), inidir);
-		inidir.erase(inidir.find_last_of('\\'));
+		inidir.Truncate(inidir.ReverseFind('\\'));
 	}
 
 	ofn.lpstrInitialDir = inidir.c_str();
@@ -540,7 +531,7 @@ bool OptionsDialogType::BrowseForSmileyPacks(int item)
 	ofn.lpstrDefExt = _T("msl");
 
 	if (GetOpenFileName(&ofn)) {
-		bkstring relpath;
+		CMString relpath;
 		pathToRelative(filename, relpath);
 		smc->SetFilename(relpath);
 
@@ -557,7 +548,7 @@ void OptionsDialogType::FilenameChanged(void)
 
 	SmileyCategoryType* smc = tmpsmcat.GetSmileyCategory(GetSelProto()); 
 	if (smc->GetFilename() != str) {
-		bkstring temp(str);
+		CMString temp(str);
 		smc->SetFilename(temp);
 		UpdateControls();
 	}
@@ -627,9 +618,9 @@ void OptionsType::Load(void)
 }
 
 
-void OptionsType::ReadPackFileName(bkstring& filename, const bkstring& name, const bkstring& defaultFilename)
+void OptionsType::ReadPackFileName(CMString& filename, const CMString& name, const CMString& defaultFilename)
 {
-	bkstring settingKey = name + _T("-filename");
+	CMString settingKey = name + _T("-filename");
 
 	DBVARIANT dbv;
 	if (!db_get_ts(NULL, "SmileyAdd", T2A_SM(settingKey.c_str()), &dbv)) {
@@ -639,15 +630,15 @@ void OptionsType::ReadPackFileName(bkstring& filename, const bkstring& name, con
 	else filename = defaultFilename;
 }
 
-void OptionsType::WritePackFileName(const bkstring& filename, const bkstring& name)
+void OptionsType::WritePackFileName(const CMString& filename, const CMString& name)
 {
-	bkstring settingKey = name + _T("-filename");
+	CMString settingKey = name + _T("-filename");
 	db_set_ts(NULL, "SmileyAdd", T2A_SM(settingKey.c_str()), 
 		filename.c_str());
 }
 
 
-void OptionsType::ReadCustomCategories(bkstring& cats)
+void OptionsType::ReadCustomCategories(CMString& cats)
 {
 	DBVARIANT dbv;
 
@@ -660,16 +651,16 @@ void OptionsType::ReadCustomCategories(bkstring& cats)
 }
 
 
-void OptionsType::WriteCustomCategories(const bkstring& cats)
+void OptionsType::WriteCustomCategories(const CMString& cats)
 {
-	if (cats.empty())
+	if (cats.IsEmpty())
 		db_unset(NULL, "SmileyAdd", "CustomCategories");
 	else
 		db_set_ts(NULL, "SmileyAdd", "CustomCategories",	cats.c_str());
 }
 
 
-void OptionsType::ReadContactCategory(HANDLE hContact, bkstring& cats)
+void OptionsType::ReadContactCategory(HANDLE hContact, CMString& cats)
 {
 	DBVARIANT dbv;
 
@@ -682,9 +673,9 @@ void OptionsType::ReadContactCategory(HANDLE hContact, bkstring& cats)
 }
 
 
-void OptionsType::WriteContactCategory(HANDLE hContact, const bkstring& cats)
+void OptionsType::WriteContactCategory(HANDLE hContact, const CMString& cats)
 {
-	if (cats.empty())
+	if (cats.IsEmpty())
 		db_unset(hContact, "SmileyAdd", "CustomCategory");
 	else
 		db_set_ts(hContact, "SmileyAdd", "CustomCategory",	cats.c_str());
diff --git a/plugins/SmileyAdd/src/options.h b/plugins/SmileyAdd/src/options.h
index 3b83b0dc8f..349fe2f9dd 100644
--- a/plugins/SmileyAdd/src/options.h
+++ b/plugins/SmileyAdd/src/options.h
@@ -45,13 +45,13 @@ public:
 
 	void Load(void);
 	void Save(void);
-	static void ReadPackFileName(bkstring& filename, const bkstring& name, 
-		const bkstring& defaultFilename);
-	static void ReadCustomCategories(bkstring& cats);
-	static void ReadContactCategory(HANDLE hContact, bkstring& cats);
-	static void WritePackFileName(const bkstring& filename, const bkstring& name);
-	static void WriteCustomCategories(const bkstring& cats);
-	static void WriteContactCategory(HANDLE hContact, const bkstring& cats);
+	static void ReadPackFileName(CMString& filename, const CMString& name, 
+		const CMString& defaultFilename);
+	static void ReadCustomCategories(CMString& cats);
+	static void ReadContactCategory(HANDLE hContact, CMString& cats);
+	static void WritePackFileName(const CMString& filename, const CMString& name);
+	static void WriteCustomCategories(const CMString& cats);
+	static void WriteContactCategory(HANDLE hContact, const CMString& cats);
 };
 
 extern OptionsType opt;
diff --git a/plugins/SmileyAdd/src/regexp/WCMatcher.cpp b/plugins/SmileyAdd/src/regexp/WCMatcher.cpp
index d74fc9f9b5..354c474bdd 100644
--- a/plugins/SmileyAdd/src/regexp/WCMatcher.cpp
+++ b/plugins/SmileyAdd/src/regexp/WCMatcher.cpp
@@ -8,173 +8,172 @@ const int WCMatcher::MATCH_ENTIRE_STRING = 0x01;
   @author   Jeffery Stuart
   @since    November 2004
   @version  1.07.00
-*/
+  */
 
-WCMatcher::WCMatcher(WCPattern * pattern, const bkstring & text)
+WCMatcher::WCMatcher(WCPattern * pattern, const CMString & text)
 {
-  pat = pattern;
-  str = &text;
-  gc = pattern->groupCount;
-  ncgc = -pattern->nonCapGroupCount;
-  flags = 0;
-  matchedSomething = false;
-  starts        = new int[gc + ncgc];
-  ends          = new int[gc + ncgc];
-  groups        = new int[gc + ncgc];
-  groupPos      = new int[gc + ncgc];
-  groupIndeces  = new int[gc + ncgc];
-  starts        = starts        + ncgc;
-  ends          = ends          + ncgc;
-  groups        = groups        + ncgc;
-  groupPos      = groupPos      + ncgc;
-  groupIndeces  = groupIndeces  + ncgc;
-  for (int i = 0; i < gc; ++i) starts[i] = ends[i] = 0;
+	pat = pattern;
+	str = &text;
+	gc = pattern->groupCount;
+	ncgc = -pattern->nonCapGroupCount;
+	flags = 0;
+	matchedSomething = false;
+	starts = new int[gc + ncgc];
+	ends = new int[gc + ncgc];
+	groups = new int[gc + ncgc];
+	groupPos = new int[gc + ncgc];
+	groupIndeces = new int[gc + ncgc];
+	starts = starts + ncgc;
+	ends = ends + ncgc;
+	groups = groups + ncgc;
+	groupPos = groupPos + ncgc;
+	groupIndeces = groupIndeces + ncgc;
+	for (int i = 0; i < gc; ++i) starts[i] = ends[i] = 0;
 }
 WCMatcher::~WCMatcher()
 {
-  delete [] (starts       - ncgc);
-  delete [] (ends         - ncgc);
-  delete [] (groups       - ncgc);
-  delete [] (groupIndeces - ncgc);
-  delete [] (groupPos     - ncgc);
+	delete[](starts - ncgc);
+	delete[](ends - ncgc);
+	delete[](groups - ncgc);
+	delete[](groupIndeces - ncgc);
+	delete[](groupPos - ncgc);
 }
 void WCMatcher::clearGroups()
 {
-  int i;
-  lm = 0;
-  for (i = 0; i < gc; ++i)    groups[i] = starts[i] = ends[i] = -1;
-  for (i = 1; i <= ncgc; ++i) groups[0 - i] = starts[0 - i] = ends[0 - i] = -1;
+	int i;
+	lm = 0;
+	for (i = 0; i < gc; ++i)    groups[i] = starts[i] = ends[i] = -1;
+	for (i = 1; i <= ncgc; ++i) groups[0 - i] = starts[0 - i] = ends[0 - i] = -1;
 }
-bkstring WCMatcher::replaceWithGroups(const bkstring & str)
+CMString WCMatcher::replaceWithGroups(const CMString & str)
 {
-  bkstring ret = L"";
-
-  bkstring t = str;
-  while (t.size() > 0)
-  {
-    if (t[0] == (wchar_t)'\\')
-    {
-      t.erase(0, 1);
-      if (t.size() == 0)
-      {
-        ret += L"\\";
-      }
-      else if (t[0] < (wchar_t)'0' || t[0] > (wchar_t)'9')
-      {
-        ret += t[0];
-        t.erase(0, 1);
-      }
-      else
-      {
-        int gn = 0;
-        while (t.size() > 0 && t[0] >= (wchar_t)'0' && t[0] <= (wchar_t)'9')
-        {
-          gn = gn * 10 + (t[0] - (wchar_t)'0');
-          t.erase(0, 1);
-        }
-        ret += getGroup(gn);
-      }
-    }
-    else
-    {
-      ret += t[0];
-      t.erase(0, 1);
-    }
-  }
-
-  return ret;
+	CMString ret = L"";
+
+	CMString t = str;
+	while (t.GetLength() > 0)
+	{
+		if (t[0] == '\\')
+		{
+			t.Delete(0);
+			if (t.GetLength() == 0)
+				ret += L"\\";
+			else if (t[0] < '0' || t[0] > '9') {
+				ret += t[0];
+				t.Delete(0);
+			}
+			else {
+				int gn = 0;
+				while (t.GetLength() > 0 && t[0] >= '0' && t[0] <= '9')
+				{
+					gn = gn * 10 + (t[0] - '0');
+					t.Delete(0);
+				}
+				ret += getGroup(gn);
+			}
+		}
+		else {
+			ret += t[0];
+			t.Delete(0);
+		}
+	}
+
+	return ret;
 }
 unsigned long WCMatcher::getFlags() const
 {
-  return flags;
+	return flags;
 }
-const bkstring& WCMatcher::getText() const
+const CMString& WCMatcher::getText() const
 {
-  return *str;
+	return *str;
 }
 
 bool WCMatcher::matches()
 {
-  flags = MATCH_ENTIRE_STRING;
-  matchedSomething = false;
-  clearGroups();
-  lm = 0;
-  return pat->head->match(*str, this, 0) == (int)str->size();
+	flags = MATCH_ENTIRE_STRING;
+	matchedSomething = false;
+	clearGroups();
+	lm = 0;
+	return pat->head->match(*str, this, 0) == (int)str->GetLength();
 }
+
 bool WCMatcher::findFirstMatch()
 {
-  starts[0] = 0;
-  flags = 0;
-  clearGroups();
-  start = 0;
-  lm = 0;
-  ends[0] = pat->head->match(*str, this, 0);
-  if (ends[0] >= 0)
-  {
-    matchedSomething = true;
-    return 1;
-  }
-  return 0;
+	starts[0] = 0;
+	flags = 0;
+	clearGroups();
+	start = 0;
+	lm = 0;
+	ends[0] = pat->head->match(*str, this, 0);
+	if (ends[0] >= 0)
+	{
+		matchedSomething = true;
+		return 1;
+	}
+	return 0;
 }
+
 bool WCMatcher::findNextMatch()
 {
-  int s = starts[0], e = ends[0];
-
-  if (!matchedSomething) return findFirstMatch();
-  if (s == e) ++e;
-  flags = 0;
-  clearGroups();
-
-  starts[0] = e;
-  if (e >= (int)str->size()) return 0;
-  start = e;
-  lm = e;
-  ends[0] = pat->head->match(*str, this, e);
-  return ends[0] >= 0;
+	int s = starts[0], e = ends[0];
+
+	if (!matchedSomething) return findFirstMatch();
+	if (s == e) ++e;
+	flags = 0;
+	clearGroups();
+
+	starts[0] = e;
+	if (e >= (int)str->GetLength()) return 0;
+	start = e;
+	lm = e;
+	ends[0] = pat->head->match(*str, this, e);
+	return ends[0] >= 0;
 }
-std::vector<bkstring> WCMatcher::findAll()
+
+std::vector<CMString> WCMatcher::findAll()
 {
-  std::vector<bkstring> ret;
-  reset();
-  while (findNextMatch())
-  {
-    ret.push_back(getGroup());
-  }
-  return ret;
+	std::vector<CMString> ret;
+	reset();
+	while (findNextMatch())
+	{
+		ret.push_back(getGroup());
+	}
+	return ret;
 }
 
 void WCMatcher::reset()
 {
-  lm = 0;
-  clearGroups();
-  matchedSomething = false;
+	lm = 0;
+	clearGroups();
+	matchedSomething = false;
 }
 
 int WCMatcher::getStartingIndex(const int groupNum) const
 {
-  if (groupNum < 0 || groupNum >= gc) return -1;
-  return starts[groupNum];
+	if (groupNum < 0 || groupNum >= gc) return -1;
+	return starts[groupNum];
 }
+
 int WCMatcher::getEndingIndex(const int groupNum) const
 {
-  if (groupNum < 0 || groupNum >= gc) return -1;
-  return ends[groupNum];
+	if (groupNum < 0 || groupNum >= gc) return -1;
+	return ends[groupNum];
 }
-bkstring WCMatcher::getGroup(const int groupNum) const
+
+CMString WCMatcher::getGroup(const int groupNum) const
 {
-  if (groupNum < 0 || groupNum >= gc) return L"";
-  if (starts[groupNum] < 0 || ends[groupNum] < 0) return L"";
-  return str->substr(starts[groupNum], ends[groupNum] - starts[groupNum]);
+	if (groupNum < 0 || groupNum >= gc) return L"";
+	if (starts[groupNum] < 0 || ends[groupNum] < 0) return L"";
+	return str->Mid(starts[groupNum], ends[groupNum] - starts[groupNum]);
 }
-std::vector<bkstring> WCMatcher::getGroups(const bool includeGroupZero) const
+
+std::vector<CMString> WCMatcher::getGroups(const bool includeGroupZero) const
 {
-  int i, start = (includeGroupZero ? 0 : 1);
-  std::vector<bkstring> ret;
-
-  for (i = start; i < gc; ++i)
-  {
-    ret.push_back(getGroup(i));
-  }
-  return ret;
-}
+	int i, start = (includeGroupZero ? 0 : 1);
+	std::vector<CMString> ret;
+
+	for (i = start; i < gc; ++i)
+		ret.push_back(getGroup(i));
 
+	return ret;
+}
diff --git a/plugins/SmileyAdd/src/regexp/WCMatcher.h b/plugins/SmileyAdd/src/regexp/WCMatcher.h
index 45610690ba..3c5df018d7 100644
--- a/plugins/SmileyAdd/src/regexp/WCMatcher.h
+++ b/plugins/SmileyAdd/src/regexp/WCMatcher.h
@@ -23,7 +23,7 @@
   invocation looks like:
   <pre>
   wchar_t buf[10000];
-  bkstring str = "\\5 (user name \\1) uses \\7 for his/her shell and \\6 is their home directory";
+  CMString str = "\\5 (user name \\1) uses \\7 for his/her shell and \\6 is their home directory";
   FILE * fp = fopen("/etc/passwd", "r");
   WCPattern::registerWCPattern("entry", "[^:]+");
   WCPattern * p = WCPattern::compile("^({entry}):({entry}):({entry}):({entry}):({entry}):({entry}):({entry})$",
@@ -92,12 +92,12 @@ class WCMatcher
       @param pattern  The pattern with which to search
       @param text     The text in which to search
      */
-    WCMatcher(WCPattern * pattern, const bkstring & text);
+    WCMatcher(WCPattern * pattern, const CMString & text);
   protected:
     /// The pattern we use to match
     WCPattern * pat;
     /// The string in which we are matching
-    const bkstring * str;
+    const CMString * str;
     /// The starting point of our match
     int start;
     /// An array of the starting positions for each group
@@ -135,7 +135,7 @@ class WCMatcher
       @param str The string in which to replace text
       @return A string with all backreferences appropriately replaced
      */
-    bkstring replaceWithGroups(const bkstring & str);
+    CMString replaceWithGroups(const CMString & str);
     /**
       The flags currently being used by the matcher.
       @return Zero
@@ -145,7 +145,7 @@ class WCMatcher
       The text being searched by the matcher.
       @return the text being searched by the matcher.
      */
-    const bkstring& getText() const;
+    const CMString& getText() const;
 
     /**
       Scans the string from start to finish for a match. The entire string must
@@ -179,7 +179,7 @@ class WCMatcher
 
       @return Every substring in order which matches the given pattern
      */
-    std::vector<bkstring> findAll();
+    std::vector<CMString> findAll();
     /**
       Resets the internal state of the matcher
      */
@@ -188,12 +188,12 @@ class WCMatcher
       Same as getText. Left n for backwards compatibilty with old source code
       @return Returns the string that is currently being used for matching
      */
-    inline const bkstring&  getString()                           const { return *str; }
+    inline const CMString&  getString()                           const { return *str; }
     /**
       Sets the string to scan
       @param newStr The string to scan for subsequent matches
      */
-    inline void         setString(const bkstring & newStr)       { str = &newStr; reset(); }
+    inline void         setString(const CMString & newStr)       { str = &newStr; reset(); }
 
     /**
       Returns the starting index of the specified group.
@@ -217,14 +217,14 @@ class WCMatcher
       @param groupNum The group to query
       @return The text of the group
      */
-    bkstring getGroup(const int groupNum = 0) const;
+    CMString getGroup(const int groupNum = 0) const;
     /**
       Returns every capture group in a vector
 
       @param includeGroupZero Whether or not include capture group zero
       @return Every capture group
      */
-    std::vector<bkstring> getGroups(const bool includeGroupZero = 0) const;
+    std::vector<CMString> getGroups(const bool includeGroupZero = 0) const;
 };
 
 #endif
diff --git a/plugins/SmileyAdd/src/regexp/WCPattern.cpp b/plugins/SmileyAdd/src/regexp/WCPattern.cpp
index e44c835b39..c6d3d500f9 100644
--- a/plugins/SmileyAdd/src/regexp/WCPattern.cpp
+++ b/plugins/SmileyAdd/src/regexp/WCPattern.cpp
@@ -13,7 +13,7 @@
   I tend to delete email if I don't recognize the name and the subject is
   something like "I Need Your Help" or "Got A Second" or "I Found It".
   "
- */
+  */
 
 /*
   Detailed documentation is provided in this class' header file
@@ -21,1173 +21,1110 @@
   @author   Jeffery Stuart
   @since    November 2004
   @version  1.07.00
-*/
+  */
 
 #include "..\general.h"
 
-std::map<bkstring, WCPattern *> WCPattern::compiledWCPatterns;
-std::map<bkstring, std::pair<bkstring, unsigned long> > WCPattern::registeredWCPatterns;
+std::map<CMString, WCPattern *> WCPattern::compiledWCPatterns;
+std::map<CMString, std::pair<CMString, unsigned long> > WCPattern::registeredWCPatterns;
 
 const int WCPattern::MIN_QMATCH = 0x00000000;
 const int WCPattern::MAX_QMATCH = 0x7FFFFFFF;
 
-const unsigned long WCPattern::CASE_INSENSITIVE       = 0x01;
-const unsigned long WCPattern::LITERAL                = 0x02;
-const unsigned long WCPattern::DOT_MATCHES_ALL        = 0x04;
-const unsigned long WCPattern::MULTILINE_MATCHING     = 0x08;
-const unsigned long WCPattern::UNIX_LINE_MODE         = 0x10;
+const unsigned long WCPattern::CASE_INSENSITIVE = 0x01;
+const unsigned long WCPattern::LITERAL = 0x02;
+const unsigned long WCPattern::DOT_MATCHES_ALL = 0x04;
+const unsigned long WCPattern::MULTILINE_MATCHING = 0x08;
+const unsigned long WCPattern::UNIX_LINE_MODE = 0x10;
 
 #define to_lower(a) (wchar_t)(UINT_PTR)CharLowerW((LPWSTR)(unsigned)a)
 #define is_alpha IsCharAlphaW
 
 #if defined(_WIN32)
-  #define str_icmp lstrcmpiW
+#define str_icmp lstrcmpiW
 #elif defined(__CYGWIN__) || defined(__APPLE__)
-  #include <wctype.h>
-  static inline int str_icmp(const wchar_t * a, const wchar_t * b)
-  {
-    while (*a && *b)
-    {
-      const int t = (int)towlower(*a) - (int)tolower(*b);
-      if (t) return t;
-      ++a; ++b;
-    }
-    if (*a)
-    {
-      if (*b) return (int)towlower(*a) - (int)tolower(*b);
-      return 1;
-    }
-    else if (*b) return 1;
-    return 0;
-  }
+#include <wctype.h>
+static inline int str_icmp(const wchar_t * a, const wchar_t * b)
+{
+	while (*a && *b)
+	{
+		const int t = (int)towlower(*a) - (int)tolower(*b);
+		if (t) return t;
+		++a; ++b;
+	}
+	if (*a)
+	{
+		if (*b) return (int)towlower(*a) - (int)tolower(*b);
+		return 1;
+	}
+	else if (*b) return 1;
+	return 0;
+}
 #else
-  #define str_icmp wcscasecmp
+#define str_icmp wcscasecmp
 #endif
 
-WCPattern::WCPattern(const bkstring & rhs)
+WCPattern::WCPattern(const CMString & rhs)
 {
-  matcher = NULL;
-  pattern = rhs;
-  curInd = 0;
-  groupCount = 0;
-  nonCapGroupCount = 0;
-  error = 0;
-  head = NULL;
+	matcher = NULL;
+	pattern = rhs;
+	curInd = 0;
+	groupCount = 0;
+	nonCapGroupCount = 0;
+	error = 0;
+	head = NULL;
 }
 // convenience function in case we want to add any extra debugging output
 void WCPattern::raiseError()
 {
-/*  switch (pattern[curInd - 1])
-  {
-  case '*':
-  case ')':
-  case '+':
-  case '?':
-  case ']':
-  case '}':
-    fwprintf(stderr, L"%s\n%*c^\n", pattern.c_str(), curInd - 1, ' ');
-    fwprintf(stderr, L"Syntax Error near here. Possible unescaped meta character.\n");
-    break;
-  default:
-    fwprintf(stderr, L"%s\n%*c^\n", pattern.c_str(), curInd - 1, ' ');
-    fwprintf(stderr, L"Syntax Error near here. \n");
-    break;
-  }*/
-  error = 1;
+	/*  switch (pattern[curInd - 1])
+	  {
+	  case '*':
+	  case ')':
+	  case '+':
+	  case '?':
+	  case ']':
+	  case '}':
+	  fwprintf(stderr, L"%s\n%*c^\n", pattern.c_str(), curInd - 1, ' ');
+	  fwprintf(stderr, L"Syntax Error near here. Possible unescaped meta character.\n");
+	  break;
+	  default:
+	  fwprintf(stderr, L"%s\n%*c^\n", pattern.c_str(), curInd - 1, ' ');
+	  fwprintf(stderr, L"Syntax Error near here. \n");
+	  break;
+	  }*/
+	error = 1;
 }
 NFAUNode * WCPattern::registerNode(NFAUNode * node)
 {
-  nodes[node] = 1;
-  return node;
+	nodes[node] = 1;
+	return node;
 }
 
-bkstring WCPattern::classUnion      (bkstring s1, bkstring s2)  const
+CMString WCPattern::classUnion(CMString s1, CMString s2) const
 {
-  wchar_t * out = new wchar_t[66000];
-  std::sort(s1.begin(), s1.end());
-  std::sort(s2.begin(), s2.end());
-  wchar_t* p = std::set_union(s1.begin(), s1.end(), s2.begin(), s2.end(), out); *p = 0;
-  bkstring ret = out;
-  delete [] out;
-  return ret;
+	wchar_t * out = new wchar_t[66000];
+	std::sort((LPTSTR)s1.GetString(), (LPTSTR)s1.GetTail());
+	std::sort((LPTSTR)s2.GetString(), (LPTSTR)s2.GetTail());
+	wchar_t* p = std::set_union(s1.GetString(), s1.GetTail(), s2.GetString(), s2.GetTail(), out); *p = 0;
+	CMString ret = out;
+	delete[] out;
+	return ret;
 }
-bkstring WCPattern::classIntersect  (bkstring s1, bkstring s2)  const
+
+CMString WCPattern::classIntersect(CMString s1, CMString s2) const
 {
-  wchar_t * out = new wchar_t[66000];
-  std::sort(s1.begin(), s1.end());
-  std::sort(s2.begin(), s2.end());
-  *std::set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(), out) = 0;
-  bkstring ret = out;
-  delete [] out;
-  return ret;
+	wchar_t * out = new wchar_t[66000];
+	std::sort((LPTSTR)s1.GetString(), (LPTSTR)s1.GetTail());
+	std::sort((LPTSTR)s2.GetString(), (LPTSTR)s2.GetTail());
+	*std::set_intersection(s1.GetString(), s1.GetTail(), s2.GetString(), s2.GetTail(), out) = 0;
+	CMString ret = out;
+	delete[] out;
+	return ret;
 }
-bkstring WCPattern::classNegate     (bkstring s1)                  const
+
+CMString WCPattern::classNegate(CMString s1) const
 {
-  wchar_t * out = new wchar_t[66000];
-  int i, ind = 0;
-  std::map<wchar_t, bool> m;
+	wchar_t * out = new wchar_t[66000];
+	int i, ind = 0;
+	std::map<wchar_t, bool> m;
 
-  for (i = 0; i < (int)s1.size(); ++i) m[s1[i]] = 1;
-  for (i = 0xFF; i >= 0; --i) if (m.find((wchar_t)i) == m.end()) out[ind++] = (wchar_t)i;
-  out[ind] = 0;
-  bkstring ret(out, ind);
-  delete [] out;
-  return ret;
+	for (i = 0; i < s1.GetLength(); ++i) m[s1[i]] = 1;
+	for (i = 0xFF; i >= 0; --i) if (m.find((wchar_t)i) == m.end()) out[ind++] = (wchar_t)i;
+	out[ind] = 0;
+	CMString ret(out, ind);
+	delete[] out;
+	return ret;
 }
-bkstring WCPattern::classCreateRange(wchar_t low, wchar_t hi)    const
+
+CMString WCPattern::classCreateRange(wchar_t low, wchar_t hi)    const
 {
-  wchar_t out[300];
-  int ind = 0;
-  while (low != hi) out[ind++] = low++;
-  out[ind++] = low;
-  return bkstring(out, ind);
+	wchar_t out[300];
+	int ind = 0;
+	while (low != hi) out[ind++] = low++;
+	out[ind++] = low;
+	return CMString(out, ind);
 }
 
 int WCPattern::getInt(int start, int end)
 {
-  int ret = 0;
-  for (; start <= end; ++start) ret = ret * 10 + (pattern[start] - (wchar_t)'0');
-  return ret;
+	int ret = 0;
+	for (; start <= end; ++start) ret = ret * 10 + (pattern[start] - '0');
+	return ret;
 }
+
 bool WCPattern::quantifyCurly(int & sNum, int & eNum)
 {
-  bool good = 1;
-  int i, ci = curInd + 1;
-  int commaInd = ci, endInd = ci, len = (int)pattern.size();
-  sNum = eNum = 0;
-
-  while (endInd   < len     && pattern[endInd  ] != (wchar_t)'}') ++endInd;
-  while (commaInd < endInd  && pattern[commaInd] != (wchar_t)',') ++commaInd;
-  if (endInd >= len) { raiseError(); return 0; }
-  for (i = ci; good && i < endInd; ++i) if (i != commaInd && !isdigit(pattern[i])) good = 0;
-  if (!good && commaInd < endInd) { raiseError(); return 0; }
-  if (!good) return 0;
-  /* so now everything in here is either a comma (and there is at most one comma) or a digit */
-  if (commaInd == ci) // {,*}
-  {
-    if (endInd == commaInd + 1)    { sNum = MIN_QMATCH;               eNum = MAX_QMATCH;                        } // {,} = *
-    else                           { sNum = MIN_QMATCH;               eNum = getInt(commaInd + 1, endInd - 1);  } // {,+}
-  }
-  else if (commaInd == endInd - 1) { sNum = getInt(ci, commaInd - 1); eNum = MAX_QMATCH;                        } // {+,}
-  else if (commaInd == endInd)     { sNum = getInt(ci, endInd - 1);   eNum = sNum;                              } // {+}
-  else                             { sNum = getInt(ci, commaInd - 1); eNum = getInt(commaInd + 1, endInd - 1);  } // {+,+}
-  curInd = endInd + 1;
-  return 1;
+	bool good = 1;
+	int i, ci = curInd + 1;
+	int commaInd = ci, endInd = ci, len = pattern.GetLength();
+	sNum = eNum = 0;
+
+	while (endInd < len     && pattern[endInd] != '}') ++endInd;
+	while (commaInd < endInd  && pattern[commaInd] != ',') ++commaInd;
+	if (endInd >= len) { raiseError(); return 0; }
+	for (i = ci; good && i < endInd; ++i) if (i != commaInd && !isdigit(pattern[i])) good = 0;
+	if (!good && commaInd < endInd) { raiseError(); return 0; }
+	if (!good) return 0;
+	/* so now everything in here is either a comma (and there is at most one comma) or a digit */
+	if (commaInd == ci) // {,*}
+	{
+		if (endInd == commaInd + 1)    { sNum = MIN_QMATCH;               eNum = MAX_QMATCH; } // {,} = *
+		else                           { sNum = MIN_QMATCH;               eNum = getInt(commaInd + 1, endInd - 1); } // {,+}
+	}
+	else if (commaInd == endInd - 1) { sNum = getInt(ci, commaInd - 1); eNum = MAX_QMATCH; } // {+,}
+	else if (commaInd == endInd)     { sNum = getInt(ci, endInd - 1);   eNum = sNum; } // {+}
+	else                             { sNum = getInt(ci, commaInd - 1); eNum = getInt(commaInd + 1, endInd - 1); } // {+,+}
+	curInd = endInd + 1;
+	return 1;
 }
+
 NFAUNode * WCPattern::quantifyGroup(NFAUNode * start, NFAUNode * stop, const int gn)
 {
-  NFAUNode * newNode = NULL;
-  int type = 0;
-
-  if (curInd < (int)pattern.size())
-  {
-    wchar_t ch = (curInd + 1 >= (int)pattern.size()) ? USHRT_MAX : pattern[curInd + 1];
-    switch (pattern[curInd])
-    {
-    case (wchar_t)'*':
-      ++curInd;
-      switch (ch)
-      {
-      case (wchar_t)'?': ++curInd; type = 1; break;
-      case (wchar_t)'+': ++curInd; type = 2; break;
-      }
-      newNode = registerNode(new NFAGroupLoopPrologueUNode(gn));
-      newNode->next = registerNode(new NFAGroupLoopUNode(start, MIN_QMATCH, MAX_QMATCH, gn, type));
-      stop->next = newNode->next;
-      return newNode;
-    case (wchar_t)'?':
-      ++curInd;
-      switch (ch)
-      {
-      case (wchar_t)'?': ++curInd; type = 1; break;
-      case (wchar_t)'+': ++curInd; type = 2; break;
-      }
-      newNode = registerNode(new NFAGroupLoopPrologueUNode(gn));
-      newNode->next = registerNode(new NFAGroupLoopUNode(start, MIN_QMATCH, 1, gn, type));
-      stop->next = newNode->next;
-      return newNode;
-    case (wchar_t)'+':
-      ++curInd;
-      switch (ch)
-      {
-      case (wchar_t)'?': ++curInd; type = 1; break;
-      case (wchar_t)'+': ++curInd; type = 2; break;
-      }
-      newNode = registerNode(new NFAGroupLoopPrologueUNode(gn));
-      newNode->next = registerNode(new NFAGroupLoopUNode(start, 1, MAX_QMATCH, gn, type));
-      stop->next = newNode->next;
-      return newNode;
-    case (wchar_t)'{':
-      {
-        int s, e;
-        if (quantifyCurly(s, e))
-        {
-          ch = (curInd < (int)pattern.size()) ? pattern[curInd] : USHRT_MAX;
-          switch (ch)
-          {
-          case (wchar_t)'?': ++curInd; type = 1; break;
-          case (wchar_t)'+': ++curInd; type = 2; break;
-          }
-          newNode = registerNode(new NFAGroupLoopPrologueUNode(gn));
-          newNode->next = registerNode(new NFAGroupLoopUNode(start, s, e, gn, type));
-          stop->next = newNode->next;
-          return newNode;
-        }
-      }
-    default:
-      break;
-    }
-  }
-  return NULL;
+	NFAUNode * newNode = NULL;
+	int type = 0;
+
+	if (curInd < pattern.GetLength()) {
+		wchar_t ch = (curInd + 1 >= pattern.GetLength()) ? USHRT_MAX : pattern[curInd + 1];
+		switch (pattern[curInd]) {
+		case '*':
+			++curInd;
+			switch (ch) {
+				case '?': ++curInd; type = 1; break;
+				case '+': ++curInd; type = 2; break;
+			}
+			newNode = registerNode(new NFAGroupLoopPrologueUNode(gn));
+			newNode->next = registerNode(new NFAGroupLoopUNode(start, MIN_QMATCH, MAX_QMATCH, gn, type));
+			stop->next = newNode->next;
+			return newNode;
+		case '?':
+			++curInd;
+			switch (ch) {
+				case '?': ++curInd; type = 1; break;
+				case '+': ++curInd; type = 2; break;
+			}
+			newNode = registerNode(new NFAGroupLoopPrologueUNode(gn));
+			newNode->next = registerNode(new NFAGroupLoopUNode(start, MIN_QMATCH, 1, gn, type));
+			stop->next = newNode->next;
+			return newNode;
+		case '+':
+			++curInd;
+			switch (ch) {
+				case '?': ++curInd; type = 1; break;
+				case '+': ++curInd; type = 2; break;
+			}
+			newNode = registerNode(new NFAGroupLoopPrologueUNode(gn));
+			newNode->next = registerNode(new NFAGroupLoopUNode(start, 1, MAX_QMATCH, gn, type));
+			stop->next = newNode->next;
+			return newNode;
+		case '{':
+			{
+				int s, e;
+				if (quantifyCurly(s, e)) {
+					ch = (curInd < pattern.GetLength()) ? pattern[curInd] : USHRT_MAX;
+					switch (ch) {
+						case '?': ++curInd; type = 1; break;
+						case '+': ++curInd; type = 2; break;
+					}
+					newNode = registerNode(new NFAGroupLoopPrologueUNode(gn));
+					newNode->next = registerNode(new NFAGroupLoopUNode(start, s, e, gn, type));
+					stop->next = newNode->next;
+					return newNode;
+				}
+			}
+		}
+	}
+	return NULL;
 }
 
 NFAUNode * WCPattern::quantify(NFAUNode * newNode)
 {
-  if (curInd < (int)pattern.size())
-  {
-    wchar_t ch = (curInd + 1 >= (int)pattern.size()) ? USHRT_MAX : pattern[curInd + 1];
-    switch (pattern[curInd])
-    {
-    case (wchar_t)'*':
-      ++curInd;
-      switch (ch)
-      {
-      case (wchar_t)'?': ++curInd; newNode = registerNode(new NFALazyQuantifierUNode      (this, newNode, MIN_QMATCH, MAX_QMATCH)); break;
-      case (wchar_t)'+': ++curInd; newNode = registerNode(new NFAPossessiveQuantifierUNode(this, newNode, MIN_QMATCH, MAX_QMATCH)); break;
-      default:            newNode = registerNode(new NFAGreedyQuantifierUNode    (this, newNode, MIN_QMATCH, MAX_QMATCH)); break;
-      }
-      break;
-    case (wchar_t)'?':
-      ++curInd;
-      switch (ch)
-      {
-      case (wchar_t)'?': ++curInd; newNode = registerNode(new NFALazyQuantifierUNode      (this, newNode, MIN_QMATCH, 1)); break;
-      case (wchar_t)'+': ++curInd; newNode = registerNode(new NFAPossessiveQuantifierUNode(this, newNode, MIN_QMATCH, 1)); break;
-      default:            newNode = registerNode(new NFAGreedyQuantifierUNode    (this, newNode, MIN_QMATCH, 1)); break;
-      }
-      break;
-    case (wchar_t)'+':
-      ++curInd;
-      switch (ch)
-      {
-      case (wchar_t)'?': ++curInd; newNode = registerNode(new NFALazyQuantifierUNode      (this, newNode, 1, MAX_QMATCH)); break;
-      case (wchar_t)'+': ++curInd; newNode = registerNode(new NFAPossessiveQuantifierUNode(this, newNode, 1, MAX_QMATCH)); break;
-      default:            newNode = registerNode(new NFAGreedyQuantifierUNode    (this, newNode, 1, MAX_QMATCH)); break;
-      }
-      break;
-    case (wchar_t)'{':
-      {
-        int s, e;
-        if (quantifyCurly(s, e))
-        {
-          ch = (curInd < (int)pattern.size()) ? pattern[curInd] : USHRT_MAX;
-          switch (ch)
-          {
-          case (wchar_t)'?': ++curInd; newNode = registerNode(new NFALazyQuantifierUNode      (this, newNode, s, e)); break;
-          case (wchar_t)'+': ++curInd; newNode = registerNode(new NFAPossessiveQuantifierUNode(this, newNode, s, e)); break;
-          default:            newNode = registerNode(new NFAGreedyQuantifierUNode    (this, newNode, s, e)); break;
-          }
-        }
-      }
-      break;
-    default:
-      break;
-    }
-  }
-  return newNode;
-}
-bkstring WCPattern::parseClass()
-{
-  bkstring t, ret = L"";
-  wchar_t ch, c1, c2;
-  bool inv = 0, neg = 0, quo = 0;
-
-  if (curInd < (int)pattern.size() && pattern[curInd] == (wchar_t)'^')
-  {
-    ++curInd;
-    neg = 1;
-  }
-  while (curInd < (int)pattern.size() && pattern[curInd] != (wchar_t)']')
-  {
-    ch = pattern[curInd++];
-    if (ch == (wchar_t)'[')
-    {
-      t = parseClass();
-      ret = classUnion(ret, t);
-    }
-    /*else if (ch == (wchar_t)'-')
-    {
-      raiseError();
-      curInd = pattern.size();
-    }*/
-    else if (ch == (wchar_t)'&' && curInd < (int)pattern.size() && pattern[curInd] == (wchar_t)'&')
-    {
-      if (pattern[++curInd] != (wchar_t)'[')
-      {
-        raiseError();
-        curInd = (int)pattern.size();
-      }
-      else
-      {
-        ++curInd;
-        t = parseClass();
-        ret = classIntersect(ret, t);
-      }
-    }
-    else if (ch == (wchar_t)'\\')
-    {
-      t = parseEscape(inv, quo);
-      if (quo)
-      {
-        raiseError();
-        curInd = (int)pattern.size();
-      }
-      else if (inv || t.size() > 1) // cant be part of a range (a-z)
-      {
-        if (inv) t = classNegate(t);
-        ret = classUnion(ret, t);
-      }
-      else if (curInd < (int)pattern.size() && pattern[curInd] == (wchar_t)'-') // part of a range (a-z)
-      {
-        c1 = t[0];
-        ++curInd;
-        if (curInd >= (int)pattern.size()) raiseError();
-        else
-        {
-          c2 = pattern[curInd++];
-          if (c2 == (wchar_t)'\\')
-          {
-            t = parseEscape(inv, quo);
-            if (quo)
-            {
-              raiseError();
-              curInd = (int)pattern.size();
-            }
-            else if (inv || t.size() > 1) raiseError();
-            else ret = classUnion(ret, classCreateRange(c1, c2));
-          }
-          else if (c2 == (wchar_t)'[' || c2 == (wchar_t)']' || c2 == (wchar_t)'-' || c2 == (wchar_t)'&')
-          {
-            raiseError();
-            curInd = (int)pattern.size();
-          }
-          else ret = classUnion(ret, classCreateRange(c1, c2));
-        }
-      }
-      else
-      {
-        ret = classUnion(ret, t);
-      }
-    }
-    else if (curInd < (int)pattern.size() && pattern[curInd] == (wchar_t)'-')
-    {
-      c1 = ch;
-      ++curInd;
-      if (curInd >= (int)pattern.size()) raiseError();
-      else
-      {
-        c2 = pattern[curInd++];
-        if (c2 == (wchar_t)'\\')
-        {
-          t = parseEscape(inv, quo);
-          if (quo)
-          {
-            raiseError();
-            curInd = (int)pattern.size();
-          }
-          else if (inv || t.size() > 1) raiseError();
-          else ret = classUnion(ret, classCreateRange(c1, c2));
-        }
-        else if (c2 == (wchar_t)'[' || c2 == (wchar_t)']' || c2 == (wchar_t)'-' || c2 == (wchar_t)'&')
-        {
-          raiseError();
-          curInd = (int)pattern.size();
-        }
-        else
-        {
-          ret = classUnion(ret, classCreateRange(c1, c2));
-        }
-      }
-    }
-    else
-    {
-      ret += L" ";
-      ret[ret.size() - 1] = ch;
-    }
-  }
-  if (curInd >= (int)pattern.size() || pattern[curInd] != (wchar_t)']')
-  {
-    raiseError();
-    ret = L"";
-  }
-  else
-  {
-    ++curInd;
-    if (neg) ret = classNegate(ret);
-  }
-  return ret;
-}
-bkstring WCPattern::parsePosix()
-{
-  bkstring s7 = pattern.substr(curInd, 7);
-  if (s7 == L"{Lower}") { curInd += 7; return L"abcdefghijklmnopqrstuvwxyz";                                                                       }
-  if (s7 == L"{Upper}") { curInd += 7; return L"ABCDEFGHIJKLMNOPQRSTUVWXYZ";                                                                       }
-  if (s7 == L"{Alpha}") { curInd += 7; return L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";                                             }
-  if (s7 == L"{Digit}") { curInd += 7; return L"0123456789";                                                                                       }
-  if (s7 == L"{Alnum}") { curInd += 7; return L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";                                   }
-  if (s7 == L"{Punct}") { curInd += 7; return L"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";                                                               }
-  if (s7 == L"{Graph}") { curInd += 7; return L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"; }
-  if (s7 == L"{Print}") { curInd += 7; return L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"; }
-  if (s7 == L"{Blank}") { curInd += 7; return L" \t";                                                                                              }
-  if (s7 == L"{Space}") { curInd += 7; return L" \t\n\x0B\f\r";                                                                                    }
-  if (s7 == L"{Cntrl}")
-  {
-	bkstring::value_type i;
-    bkstring s = L" ";
-
-    for (i = 0; i < 5; ++i) s += s;
-    s += L" ";
-    for (i = 0; i <= 0x1F; ++i) s[i] = i;
-    s[0x20] = 0x7F;
-    curInd += 7;
-    return s;
-  }
-  if (s7 == L"{ASCII}")
-  {
-    bkstring s(0x80, (wchar_t)' ');
-    for (bkstring::value_type i = 0; i <= 0x7f; ++i) s[i] = i;
-    curInd += 7;
-    return s;
-  }
-  if (pattern.substr(curInd, 8) == L"{XDigit}") { curInd += 8; return L"abcdefABCDEF0123456789"; }
-  raiseError();
-  return L"";
+	if (curInd < pattern.GetLength()) {
+		wchar_t ch = (curInd + 1 >= pattern.GetLength()) ? USHRT_MAX : pattern[curInd + 1];
+		switch (pattern[curInd]) {
+		case '*':
+			++curInd;
+			switch (ch) {
+				case '?': ++curInd; newNode = registerNode(new NFALazyQuantifierUNode(this, newNode, MIN_QMATCH, MAX_QMATCH)); break;
+				case '+': ++curInd; newNode = registerNode(new NFAPossessiveQuantifierUNode(this, newNode, MIN_QMATCH, MAX_QMATCH)); break;
+				default:            newNode = registerNode(new NFAGreedyQuantifierUNode(this, newNode, MIN_QMATCH, MAX_QMATCH)); break;
+			}
+			break;
+		case '?':
+			++curInd;
+			switch (ch) {
+				case '?': ++curInd; newNode = registerNode(new NFALazyQuantifierUNode(this, newNode, MIN_QMATCH, 1)); break;
+				case '+': ++curInd; newNode = registerNode(new NFAPossessiveQuantifierUNode(this, newNode, MIN_QMATCH, 1)); break;
+				default:            newNode = registerNode(new NFAGreedyQuantifierUNode(this, newNode, MIN_QMATCH, 1)); break;
+			}
+			break;
+		case '+':
+			++curInd;
+			switch (ch) {
+				case '?': ++curInd; newNode = registerNode(new NFALazyQuantifierUNode(this, newNode, 1, MAX_QMATCH)); break;
+				case '+': ++curInd; newNode = registerNode(new NFAPossessiveQuantifierUNode(this, newNode, 1, MAX_QMATCH)); break;
+				default:            newNode = registerNode(new NFAGreedyQuantifierUNode(this, newNode, 1, MAX_QMATCH)); break;
+			}
+			break;
+		case '{':
+			int s, e;
+			if (quantifyCurly(s, e)) {
+				ch = (curInd < pattern.GetLength()) ? pattern[curInd] : USHRT_MAX;
+				switch (ch) {
+					case '?': ++curInd; newNode = registerNode(new NFALazyQuantifierUNode(this, newNode, s, e)); break;
+					case '+': ++curInd; newNode = registerNode(new NFAPossessiveQuantifierUNode(this, newNode, s, e)); break;
+					default:            newNode = registerNode(new NFAGreedyQuantifierUNode(this, newNode, s, e)); break;
+				}
+			}
+			break;
+		}
+	}
+	return newNode;
+}
+CMString WCPattern::parseClass()
+{
+	CMString t, ret = L"";
+	wchar_t ch, c1, c2;
+	bool inv = 0, neg = 0, quo = 0;
+
+	if (curInd < pattern.GetLength() && pattern[curInd] == '^')
+	{
+		++curInd;
+		neg = 1;
+	}
+	while (curInd < pattern.GetLength() && pattern[curInd] != ']')
+	{
+		ch = pattern[curInd++];
+		if (ch == '[')
+		{
+			t = parseClass();
+			ret = classUnion(ret, t);
+		}
+		/*else if (ch == '-')
+		{
+		raiseError();
+		curInd = pattern.GetLength();
+		}*/
+		else if (ch == '&' && curInd < pattern.GetLength() && pattern[curInd] == '&') {
+			if (pattern[++curInd] != '[') {
+				raiseError();
+				curInd = pattern.GetLength();
+			}
+			else {
+				++curInd;
+				t = parseClass();
+				ret = classIntersect(ret, t);
+			}
+		}
+		else if (ch == '\\')
+		{
+			t = parseEscape(inv, quo);
+			if (quo) {
+				raiseError();
+				curInd = pattern.GetLength();
+			}
+			else if (inv || t.GetLength() > 1) { // cant be part of a range (a-z)
+				if (inv) t = classNegate(t);
+				ret = classUnion(ret, t);
+			}
+			else if (curInd < pattern.GetLength() && pattern[curInd] == '-') { // part of a range (a-z) 
+				c1 = t[0];
+				++curInd;
+				if (curInd >= pattern.GetLength()) raiseError();
+				else {
+					c2 = pattern[curInd++];
+					if (c2 == '\\')
+					{
+						t = parseEscape(inv, quo);
+						if (quo)
+						{
+							raiseError();
+							curInd = pattern.GetLength();
+						}
+						else if (inv || t.GetLength() > 1) raiseError();
+						else ret = classUnion(ret, classCreateRange(c1, c2));
+					}
+					else if (c2 == '[' || c2 == ']' || c2 == '-' || c2 == '&')
+					{
+						raiseError();
+						curInd = pattern.GetLength();
+					}
+					else ret = classUnion(ret, classCreateRange(c1, c2));
+				}
+			}
+			else
+			{
+				ret = classUnion(ret, t);
+			}
+		}
+		else if (curInd < pattern.GetLength() && pattern[curInd] == '-')
+		{
+			c1 = ch;
+			++curInd;
+			if (curInd >= pattern.GetLength()) raiseError();
+			else
+			{
+				c2 = pattern[curInd++];
+				if (c2 == '\\')
+				{
+					t = parseEscape(inv, quo);
+					if (quo)
+					{
+						raiseError();
+						curInd = pattern.GetLength();
+					}
+					else if (inv || t.GetLength() > 1) raiseError();
+					else ret = classUnion(ret, classCreateRange(c1, c2));
+				}
+				else if (c2 == '[' || c2 == ']' || c2 == '-' || c2 == '&')
+				{
+					raiseError();
+					curInd = pattern.GetLength();
+				}
+				else
+				{
+					ret = classUnion(ret, classCreateRange(c1, c2));
+				}
+			}
+		}
+		else ret.AppendChar(ch);
+	}
+	if (curInd >= pattern.GetLength() || pattern[curInd] != ']')
+	{
+		raiseError();
+		ret = L"";
+	}
+	else
+	{
+		++curInd;
+		if (neg) ret = classNegate(ret);
+	}
+	return ret;
+}
+CMString WCPattern::parsePosix()
+{
+	CMString s7 = pattern.Mid(curInd, 7);
+	if (s7 == L"{Lower}") { curInd += 7; return L"abcdefghijklmnopqrstuvwxyz"; }
+	if (s7 == L"{Upper}") { curInd += 7; return L"ABCDEFGHIJKLMNOPQRSTUVWXYZ"; }
+	if (s7 == L"{Alpha}") { curInd += 7; return L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; }
+	if (s7 == L"{Digit}") { curInd += 7; return L"0123456789"; }
+	if (s7 == L"{Alnum}") { curInd += 7; return L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; }
+	if (s7 == L"{Punct}") { curInd += 7; return L"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"; }
+	if (s7 == L"{Graph}") { curInd += 7; return L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"; }
+	if (s7 == L"{Print}") { curInd += 7; return L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"; }
+	if (s7 == L"{Blank}") { curInd += 7; return L" \t"; }
+	if (s7 == L"{Space}") { curInd += 7; return L" \t\n\x0B\f\r"; }
+	if (s7 == L"{Cntrl}")
+	{
+		TCHAR i;
+		CMString s = L" ";
+
+		for (i = 0; i < 5; ++i) s += s;
+		s += L" ";
+		for (i = 0; i <= 0x1F; ++i)
+			s.SetAt(i, i);
+		s.SetAt(0x20, 0x7F);
+		curInd += 7;
+		return s;
+	}
+	if (s7 == L"{ASCII}")
+	{
+		CMString s(' ', 0x80);
+		for (int i = 0; i <= 0x7f; ++i) s.SetAt(i, i);
+		curInd += 7;
+		return s;
+	}
+	if (pattern.Mid(curInd, 8) == L"{XDigit}") { curInd += 8; return L"abcdefABCDEF0123456789"; }
+	raiseError();
+	return L"";
 }
 NFAUNode * WCPattern::parseBackref()
 {
-  #define is_dig(x) ((x) >= (wchar_t)'0' && (x) <= (wchar_t)'9')
-  #define to_int(x) ((x) - (wchar_t)'0')
-  int ci = curInd;
-  int oldRef = 0, ref = 0;
-
-  while (ci < (int)pattern.size() && is_dig(pattern[ci]) && (ref < 10 || ref < groupCount))
-  {
-    oldRef = ref;
-    ref = ref * 10 + to_int(pattern[ci++]);
-  }
-  if (ci == (int)pattern.size())
-  {
-    oldRef = ref;
-    ++ci;
-  }
-  if (oldRef < 0 || ci <= curInd)
-  {
-    raiseError();
-    return registerNode(new NFAReferenceUNode(-1));
-  }
-  curInd = ci;
-  return registerNode(new NFAReferenceUNode(ref));
-
-  #undef is_dig
-  #undef to_int
-}
-bkstring WCPattern::parseOctal()
-{
-  #define islowoc(x)  ((x) >= (wchar_t)'0' && (x) <= (wchar_t)'3')
-  #define isoc(x)     ((x) >= (wchar_t)'0' && (x) <= (wchar_t)'7')
-  #define fromoc(x)   ((x) - (wchar_t)'0')
-  int ci = curInd;
-  wchar_t ch1 = (ci + 0 < (int)pattern.size()) ? pattern[ci + 0] : USHRT_MAX;
-  wchar_t ch2 = (ci + 1 < (int)pattern.size()) ? pattern[ci + 1] : USHRT_MAX;
-  wchar_t ch3 = (ci + 2 < (int)pattern.size()) ? pattern[ci + 2] : USHRT_MAX;
-  bkstring s = L" ";
-
-  if (islowoc(ch1) && isoc(ch2))
-  {
-    curInd += 2;
-    s[0] = fromoc(ch1) * 8 + fromoc(ch2);
-    if (isoc(ch3))
-    {
-      ++curInd;
-      s[0] = s[0] * 8 + fromoc(ch3);
-    }
-  }
-  else if (isoc(ch1) && isoc(ch2))
-  {
-    curInd += 2;
-    s[0] = fromoc(ch1) * 8 + fromoc(ch2);
-  }
-  else raiseError();
-
-  return s;
-  #undef islowoc
-  #undef isoc
-  #undef fromoc
-}
-bkstring WCPattern::parseHex()
-{
-  #define to_low(x)   (((x) >= (wchar_t)'A' && (x) <= (wchar_t)'Z') ? ((x) - (wchar_t)'A' + (wchar_t)'a') : (x))
-  #define is_dig(x)   ((x) >= (wchar_t)'0' && (x) <= (wchar_t)'9')
-  #define is_hex(x)   (is_dig(x) || (to_low(x) >= (wchar_t)'a' && to_low(x) <= (wchar_t)'f'))
-  #define to_int(x)   ((is_dig(x)) ? ((x) - (wchar_t)'0') : (to_low(x) - (wchar_t)'a' + 10))
-
-  int ci = curInd;
-  wchar_t ch1 = (ci + 0 < (int)pattern.size()) ? pattern[ci + 0] : USHRT_MAX;
-  wchar_t ch2 = (ci + 1 < (int)pattern.size()) ? pattern[ci + 1] : USHRT_MAX;
-  wchar_t ch3 = (ci + 2 < (int)pattern.size()) ? pattern[ci + 2] : USHRT_MAX;
-  wchar_t ch4 = (ci + 3 < (int)pattern.size()) ? pattern[ci + 3] : USHRT_MAX;
-  bkstring s = L" ";
-
-  if (is_hex(ch1) && is_hex(ch2) && is_hex(ch3) && is_hex(ch4))
-  {
-    curInd += 2;
-    s[0] = (to_int(ch1) << 12 & 0xF000) | (to_int(ch2) << 8 & 0x0F00) |
-           (to_int(ch3) <<  4 & 0x0F00) | (to_int(ch4)      & 0x000F);
-  }
-  else if (is_hex(ch1) && is_hex(ch2))
-  {
-    curInd += 2;
-    s[0] = (to_int(ch1) << 4 & 0xF0) | (to_int(ch2) & 0x0F);
-  }
-
-  return s;
-  #undef to_low
-  #undef is_dig
-  #undef is_hex
-  #undef to_int
-}
-bkstring WCPattern::parseEscape(bool & inv, bool & quo)
-{
-  wchar_t ch = pattern[curInd++];
-  bkstring classes = L"";
-
-  if (curInd > (int)pattern.size())
-  {
-    raiseError();
-    return NULL;
-  }
-
-  quo = 0;
-  inv = 0;
-  switch (ch)
-  {
-  case (wchar_t)'p': classes = parsePosix();                                                         break;
-  case (wchar_t)'P': classes = L"!!"; classes += parsePosix();                                        break;
-  case (wchar_t)'d': classes = L"0123456789";                                                         break;
-  case (wchar_t)'D': classes = L"!!0123456789";                                                       break;
-  case (wchar_t)'s': classes = L" \t\r\n\f";                                                          break;
-  case (wchar_t)'S': classes = L"!! \t\r\n\f";                                                        break;
-  case (wchar_t)'w': classes = L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";    break;
-  case (wchar_t)'W': classes = L"!!abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";  break;
-  case (wchar_t)'0': classes = parseOctal(); break;
-  case (wchar_t)'x': classes = parseHex();   break;
-
-  case (wchar_t)'Q': quo = 1;        break;
-  case (wchar_t)'t': classes = L"\t"; break;
-  case (wchar_t)'r': classes = L"\r"; break;
-  case (wchar_t)'n': classes = L"\n"; break;
-  case (wchar_t)'f': classes = L"\f"; break;
-  case (wchar_t)'a': classes = L"\a"; break;
-  case (wchar_t)'e': classes = L"\r"; break;
-  default:  classes = L" "; classes[0] = ch; break;
-  }
-  if (classes.substr(0, 2) == L"!!")
-  {
-    classes = classes.substr(2);
-    inv = 1;
-  }
-  return classes;
-}
-NFAUNode * WCPattern::parseRegisteredWCPattern(NFAUNode ** end)
-{
-  int i, j;
-  bkstring s;
-  NFAUNode * ret = NULL;
-  for (i = curInd; i < (int)pattern.size() && pattern[i] != (wchar_t)'}'; ++i) { }
-  if (pattern[i] != (wchar_t)'}') { raiseError(); return NULL; }
-  if (i == curInd + 1)   { raiseError(); return NULL; } // {}
-  if (
-      !(
-        (pattern[curInd] >= (wchar_t)'a' && pattern[curInd] <= (wchar_t)'z') ||
-        (pattern[curInd] >= (wchar_t)'A' && pattern[curInd] <= (wchar_t)'Z') ||
-        (pattern[curInd] == (wchar_t)'_')
-       )
-     )
-  {
-    raiseError();
-    return NULL;
-  }
-  for (j = curInd; !error && j < i; ++j)
-  {
-    if (
-        !(
-          (pattern[j] >= (wchar_t)'a' && pattern[j] <= (wchar_t)'z') ||
-          (pattern[j] >= (wchar_t)'A' && pattern[j] <= (wchar_t)'Z') ||
-          (pattern[j] >= (wchar_t)'0' && pattern[j] <= (wchar_t)'9') ||
-          (pattern[j] == (wchar_t)'_')))
-    {
-      raiseError();
-      return NULL;
-    }
-  }
-  s = pattern.substr(curInd, i - curInd);
-  if (registeredWCPatterns.find(s) == registeredWCPatterns.end()) raiseError();
-  else
-  {
-    unsigned long oflags = flags;
-    bkstring op = pattern;
-    int ci = i + 1;
-
-    pattern = registeredWCPatterns[s].first;
-    curInd = 0;
-    flags = registeredWCPatterns[s].second;
-
-    --groupCount;
-    ret = parse(0, 0, end);
-
-    pattern = op;
-    curInd = ci;
-    flags = oflags;
-  }
-  if (error) { *end = ret = NULL; }
-  return ret;
+#define is_dig(x) ((x) >= '0' && (x) <= '9')
+#define to_int(x) ((x) - '0')
+	int ci = curInd;
+	int oldRef = 0, ref = 0;
+
+	while (ci < pattern.GetLength() && is_dig(pattern[ci]) && (ref < 10 || ref < groupCount))
+	{
+		oldRef = ref;
+		ref = ref * 10 + to_int(pattern[ci++]);
+	}
+	if (ci == pattern.GetLength())
+	{
+		oldRef = ref;
+		++ci;
+	}
+	if (oldRef < 0 || ci <= curInd)
+	{
+		raiseError();
+		return registerNode(new NFAReferenceUNode(-1));
+	}
+	curInd = ci;
+	return registerNode(new NFAReferenceUNode(ref));
+
+#undef is_dig
+#undef to_int
+}
+CMString WCPattern::parseOctal()
+{
+#define islowoc(x)  ((x) >= '0' && (x) <= '3')
+#define isoc(x)     ((x) >= '0' && (x) <= '7')
+#define fromoc(x)   ((x) - '0')
+	int ci = curInd;
+	wchar_t ch1 = (ci + 0 < pattern.GetLength()) ? pattern[ci + 0] : USHRT_MAX;
+	wchar_t ch2 = (ci + 1 < pattern.GetLength()) ? pattern[ci + 1] : USHRT_MAX;
+	wchar_t ch3 = (ci + 2 < pattern.GetLength()) ? pattern[ci + 2] : USHRT_MAX;
+	CMString s = L" ";
+
+	if (islowoc(ch1) && isoc(ch2)) {
+		curInd += 2;
+		s.SetAt(0, fromoc(ch1) * 8 + fromoc(ch2));
+		if (isoc(ch3)) {
+			++curInd;
+			s.SetAt(0, s[0] * 8 + fromoc(ch3));
+		}
+	}
+	else if (isoc(ch1) && isoc(ch2)) {
+		curInd += 2;
+		s.SetAt(0, fromoc(ch1) * 8 + fromoc(ch2));
+	}
+	else raiseError();
+
+	return s;
+#undef islowoc
+#undef isoc
+#undef fromoc
+}
+CMString WCPattern::parseHex()
+{
+#define to_low(x)   (((x) >= 'A' && (x) <= 'Z') ? ((x) - 'A' + 'a') : (x))
+#define is_dig(x)   ((x) >= '0' && (x) <= '9')
+#define is_hex(x)   (is_dig(x) || (to_low(x) >= 'a' && to_low(x) <= 'f'))
+#define to_int(x)   ((is_dig(x)) ? ((x) - '0') : (to_low(x) - 'a' + 10))
+
+	int ci = curInd;
+	wchar_t ch1 = (ci + 0 < pattern.GetLength()) ? pattern[ci + 0] : USHRT_MAX;
+	wchar_t ch2 = (ci + 1 < pattern.GetLength()) ? pattern[ci + 1] : USHRT_MAX;
+	wchar_t ch3 = (ci + 2 < pattern.GetLength()) ? pattern[ci + 2] : USHRT_MAX;
+	wchar_t ch4 = (ci + 3 < pattern.GetLength()) ? pattern[ci + 3] : USHRT_MAX;
+	CMString s = L" ";
+
+	if (is_hex(ch1) && is_hex(ch2) && is_hex(ch3) && is_hex(ch4))
+	{
+		curInd += 2;
+		s.SetAt(0, (to_int(ch1) << 12 & 0xF000) | (to_int(ch2) << 8 & 0x0F00) |
+			(to_int(ch3) << 4 & 0x0F00) | (to_int(ch4) & 0x000F));
+	}
+	else if (is_hex(ch1) && is_hex(ch2))
+	{
+		curInd += 2;
+		s.SetAt(0, (to_int(ch1) << 4 & 0xF0) | (to_int(ch2) & 0x0F));
+	}
+
+	return s;
+#undef to_low
+#undef is_dig
+#undef is_hex
+#undef to_int
+}
+CMString WCPattern::parseEscape(bool & inv, bool & quo)
+{
+	wchar_t ch = pattern[curInd++];
+	CMString classes;
+
+	if (curInd > pattern.GetLength()) {
+		raiseError();
+		return "";
+	}
+
+	quo = 0;
+	inv = 0;
+	switch (ch) {
+		case 'p': classes = parsePosix();                                                         break;
+		case 'P': classes = L"!!"; classes += parsePosix();                                        break;
+		case 'd': classes = L"0123456789";                                                         break;
+		case 'D': classes = L"!!0123456789";                                                       break;
+		case 's': classes = L" \t\r\n\f";                                                          break;
+		case 'S': classes = L"!! \t\r\n\f";                                                        break;
+		case 'w': classes = L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";    break;
+		case 'W': classes = L"!!abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";  break;
+		case '0': classes = parseOctal(); break;
+		case 'x': classes = parseHex();   break;
+		  
+		case 'Q': quo = 1;        break;
+		case 't': classes = L"\t"; break;
+		case 'r': classes = L"\r"; break;
+		case 'n': classes = L"\n"; break;
+		case 'f': classes = L"\f"; break;
+		case 'a': classes = L"\a"; break;
+		case 'e': classes = L"\r"; break;
+		default:  classes.AppendChar(ch); break;
+	}
+
+	if (classes.Mid(0, 2) == L"!!") {
+		classes = classes.Mid(2);
+		inv = 1;
+	}
+	return classes;
+}
+NFAUNode * WCPattern::parseRegisteredWCPattern(NFAUNode **end)
+{
+	int i, j;
+	CMString s;
+	NFAUNode * ret = NULL;
+	for (i = curInd; i < pattern.GetLength() && pattern[i] != '}'; ++i) {}
+	if (pattern[i] != '}') { raiseError(); return NULL; }
+	if (i == curInd + 1)   { raiseError(); return NULL; } // {}
+	if (
+		!(
+		(pattern[curInd] >= 'a' && pattern[curInd] <= 'z') ||
+		(pattern[curInd] >= 'A' && pattern[curInd] <= 'Z') ||
+		(pattern[curInd] == '_')
+		)
+		)
+	{
+		raiseError();
+		return NULL;
+	}
+	for (j = curInd; !error && j < i; ++j)
+	{
+		if (
+			!(
+			(pattern[j] >= 'a' && pattern[j] <= 'z') ||
+			(pattern[j] >= 'A' && pattern[j] <= 'Z') ||
+			(pattern[j] >= '0' && pattern[j] <= '9') ||
+			(pattern[j] == '_')))
+		{
+			raiseError();
+			return NULL;
+		}
+	}
+	s = pattern.Mid(curInd, i - curInd);
+	if (registeredWCPatterns.find(s) == registeredWCPatterns.end()) raiseError();
+	else
+	{
+		unsigned long oflags = flags;
+		CMString op = pattern;
+		int ci = i + 1;
+
+		pattern = registeredWCPatterns[s].first;
+		curInd = 0;
+		flags = registeredWCPatterns[s].second;
+
+		--groupCount;
+		ret = parse(0, 0, end);
+
+		pattern = op;
+		curInd = ci;
+		flags = oflags;
+	}
+	if (error) { *end = ret = NULL; }
+	return ret;
 }
 
 // look behind should interpret everything as a literal (except \\) since the
 // pattern must have a concrete length
 NFAUNode * WCPattern::parseBehind(const bool pos, NFAUNode ** end)
 {
-  bkstring t = L"";
-  while (curInd < (int)pattern.size() && pattern[curInd] != (wchar_t)')')
-  {
-    wchar_t ch = pattern[curInd++];
-    t += L" ";
-    if (ch == (wchar_t)'\\')
-    {
-      if (curInd + 1 >= (int)pattern.size())
-      {
-        raiseError();
-        return *end = registerNode(new NFACharUNode((wchar_t)' '));
-      }
-      ch = pattern[curInd++];
-    }
-    t[t.size() - 1] = ch;
-  }
-  if (curInd >= (int)pattern.size() || pattern[curInd] != (wchar_t)')') raiseError();
-  else ++curInd;
-  return *end = registerNode(new NFALookBehindUNode(t, pos));
+	CMString t = L"";
+	while (curInd < pattern.GetLength() && pattern[curInd] != ')')
+	{
+		wchar_t ch = pattern[curInd++];
+		if (ch == '\\')
+		{
+			if (curInd + 1 >= pattern.GetLength())
+			{
+				raiseError();
+				return *end = registerNode(new NFACharUNode(' '));
+			}
+			ch = pattern[curInd++];
+		}
+		t.AppendChar(ch);
+	}
+	if (curInd >= pattern.GetLength() || pattern[curInd] != ')') raiseError();
+	else ++curInd;
+	return *end = registerNode(new NFALookBehindUNode(t, pos));
 }
 NFAUNode * WCPattern::parseQuote()
 {
-  bool done = 0;
-  bkstring s = L"";
-
-  while (!done)
-  {
-    if      (curInd >= (int)pattern.size())
-    {
-      raiseError();
-      done = 1;
-    }
-    else if (pattern.substr(curInd, 2) == L"\\E")
-    {
-      curInd += 2;
-      done = 1;
-    }
-    else if (pattern[curInd] == (wchar_t)'\\')
-    {
-      s += L" ";
-      s[s.size() - 1] = pattern[++curInd];
-      ++curInd;
-    }
-    else
-    {
-      s += L" ";
-      s[s.size() - 1] = pattern[curInd++];
-    }
-  }
-  if ((flags & WCPattern::CASE_INSENSITIVE) != 0) return registerNode(new NFACIQuoteUNode(s));
-  return registerNode(new NFAQuoteUNode(s));
+	bool done = 0;
+	CMString s = L"";
+
+	while (!done)
+	{
+		if (curInd >= pattern.GetLength())
+		{
+			raiseError();
+			done = 1;
+		}
+		else if (pattern.Mid(curInd, 2) == L"\\E")
+		{
+			curInd += 2;
+			done = 1;
+		}
+		else if (pattern[curInd] == '\\')
+		{
+			s.AppendChar(pattern[++curInd]);
+			++curInd;
+		}
+		else s.AppendChar(pattern[curInd++]);
+	}
+	if ((flags & WCPattern::CASE_INSENSITIVE) != 0) return registerNode(new NFACIQuoteUNode(s));
+	return registerNode(new NFAQuoteUNode(s));
 }
 NFAUNode * WCPattern::parse(const bool inParen, const bool inOr, NFAUNode ** end)
 {
-  NFAUNode * start, * cur, * next = NULL;
-  bkstring t;
-  int grc = groupCount++;
-  bool inv, quo;
-  bool ahead = 0, pos = 0, noncap = 0, indep = 0;
-  unsigned long oldFlags = flags;
-
-  if (inParen)
-  {
-    if (pattern[curInd] == (wchar_t)'?')
-    {
-      ++curInd;
-      --groupCount;
-      if      (pattern[curInd]           == (wchar_t)':')   { noncap = 1; ++curInd;     grc = --nonCapGroupCount; }
-      else if (pattern[curInd]           == (wchar_t)'=')   { ++curInd;     ahead = 1;  pos = 1;                  }
-      else if (pattern[curInd]           == (wchar_t)'!')   { ++curInd;     ahead = 1;  pos = 0;                  }
-      else if (pattern.substr(curInd, 2) == L"<=")  { curInd += 2;  return parseBehind(1, end);                   }
-      else if (pattern.substr(curInd, 2) == L"<!")  { curInd += 2;  return parseBehind(0, end);                   }
-      else if (pattern[curInd]           == (wchar_t)'>')   { ++curInd;     indep = 1;                            }
-      else
-      {
-        bool negate = false, done = false;
-        while (!done)
-        {
-          if (curInd >= (int)pattern.size())
-          {
-            raiseError();
-            return NULL;
-          }
-          else if (negate)
-          {
-            switch (pattern[curInd])
-            {
-            case (wchar_t)'i': flags &= ~WCPattern::CASE_INSENSITIVE;   break;
-            case (wchar_t)'d': flags &= ~WCPattern::UNIX_LINE_MODE;     break;
-            case (wchar_t)'m': flags &= ~WCPattern::MULTILINE_MATCHING; break;
-            case (wchar_t)'s': flags &= ~WCPattern::DOT_MATCHES_ALL;    break;
-            case (wchar_t)':': done = true;                             break;
-            case (wchar_t)')':
-              ++curInd;
-              *end = registerNode(new NFALookBehindUNode(L"", true));
-              return *end;
-            case (wchar_t)'-':
-            default: raiseError(); return NULL;
-            }
-          }
-          else
-          {
-            switch (pattern[curInd])
-            {
-            case (wchar_t)'i': flags |= WCPattern::CASE_INSENSITIVE;    break;
-            case (wchar_t)'d': flags |= WCPattern::UNIX_LINE_MODE;      break;
-            case (wchar_t)'m': flags |= WCPattern::MULTILINE_MATCHING;  break;
-            case (wchar_t)'s': flags |= WCPattern::DOT_MATCHES_ALL;     break;
-            case (wchar_t)':': done = true;                             break;
-            case (wchar_t)'-': negate = true;                           break;
-            case (wchar_t)')':
-              ++curInd;
-              *end = registerNode(new NFALookBehindUNode(L"", true));
-              return *end;
-            default:  raiseError(); return NULL;
-            }
-          }
-          ++curInd;
-        }
-        noncap = 1;
-        grc = --nonCapGroupCount;
-      }
-
-      if (noncap) cur = start = registerNode(new NFAGroupHeadUNode(grc));
-      else        cur = start = registerNode(new NFASubStartUNode);
-    }
-    else cur = start = registerNode(new NFAGroupHeadUNode(grc));
-  }
-  else cur = start = registerNode(new NFASubStartUNode);
-  while (curInd < (int)pattern.size())
-  {
-    wchar_t ch = pattern[curInd++];
-
-    next = NULL;
-    if (error) return NULL;
-    switch (ch)
-    {
-    case (wchar_t)'^':
-      if ((flags & WCPattern::MULTILINE_MATCHING) != 0) next = registerNode(new NFAStartOfLineUNode);
-      else                                            next = registerNode(new NFAStartOfInputUNode);
-      break;
-    case (wchar_t)'$':
-      if ((flags & WCPattern::MULTILINE_MATCHING) != 0) next = registerNode(new NFAEndOfLineUNode);
-      else                                            next = registerNode(new NFAEndOfInputUNode(0));
-      break;
-    case (wchar_t)'|':
-      --groupCount;
-      cur->next = registerNode(new NFAAcceptUNode);
-      cur = start = registerNode(new NFAOrUNode(start, parse(inParen, 1)));
-      break;
-    case (wchar_t)'\\':
-      if      (curInd < (int)pattern.size())
-      {
-        bool eoi = 0;
-        switch (pattern[curInd])
-        {
-        case (wchar_t)'1':
-        case (wchar_t)'2':
-        case (wchar_t)'3':
-        case (wchar_t)'4':
-        case (wchar_t)'5':
-        case (wchar_t)'6':
-        case (wchar_t)'7':
-        case (wchar_t)'8':
-        case (wchar_t)'9': next = parseBackref(); break;
-        case (wchar_t)'A': ++curInd; next = registerNode(new NFAStartOfInputUNode);     break;
-        case (wchar_t)'B': ++curInd; next = registerNode(new NFAWordBoundaryUNode(0));  break;
-        case (wchar_t)'b': ++curInd; next = registerNode(new NFAWordBoundaryUNode(1));  break;
-        case (wchar_t)'G': ++curInd; next = registerNode(new NFAEndOfMatchUNode);       break;
-        case (wchar_t)'Z': eoi = 1;
-        case (wchar_t)'z': ++curInd; next = registerNode(new NFAEndOfInputUNode(eoi));  break;
-        default:
-          t = parseEscape(inv, quo);
-          //printf("inv quo classes { %c %c %s }\n", inv ? (wchar_t)'t' : (wchar_t)'f', quo ? (wchar_t)'t' : (wchar_t)'f', t.c_str());
-          if (!quo)
-          {
-            if (t.size() > 1 || inv)
-            {
-              if ((flags & WCPattern::CASE_INSENSITIVE) != 0) next = registerNode(new NFACIClassUNode(t, inv));
-              else                                            next = registerNode(new NFAClassUNode(t, inv));
-            }
-            else
-            {
-              next = registerNode(new NFACharUNode(t[0]));
-            }
-          }
-          else
-          {
-            next = parseQuote();
-          }
-        }
-      }
-      else raiseError();
-      break;
-    case (wchar_t)'[':
-      if ((flags & WCPattern::CASE_INSENSITIVE) == 0)
-      {
-        NFAClassUNode * clazz = new NFAClassUNode();
-        bkstring s = parseClass();
-        for (int i = 0; i < (int)s.size(); ++i) clazz->vals[s[i]] = 1;
-        next = registerNode(clazz);
-      }
-      else
-      {
-        NFACIClassUNode * clazz = new NFACIClassUNode();
-        bkstring s = parseClass();
-        for (int i = 0; i < (int)s.size(); ++i) clazz->vals[to_lower(s[i])] = 1;
-        next = registerNode(clazz);
-      }
-      break;
-    case (wchar_t)'.':
-      {
-        bool useN = 1, useR = 1;
-        NFAClassUNode * clazz = new NFAClassUNode(1);
-        if ((flags & WCPattern::UNIX_LINE_MODE)  != 0) useR = 0;
-        if ((flags & WCPattern::DOT_MATCHES_ALL) != 0) useN = useR = 0;
-        if (useN) clazz->vals[(wchar_t)'\n'] = 1;
-        if (useR) clazz->vals[(wchar_t)'\r'] = 1;
-        next = registerNode(clazz);
-      }
-      break;
-    case (wchar_t)'(':
-      {
-        NFAUNode * end, * t1, * t2;
-        t1 = parse(1, 0, &end);
-        if (!t1) raiseError();
-        else if (t1->isGroupHeadNode() && (t2 = quantifyGroup(t1, end, grc)) != NULL)
-        {
-          cur->next = t2;
-          cur = t2->next;
-        }
-        else
-        {
-          cur->next = t1;
-          cur = end;
-        }
-      }
-      break;
-    case (wchar_t)')':
-      if (!inParen) raiseError();
-      else if (inOr)
-      {
-        --curInd;
-        cur = cur->next = registerNode(new NFAAcceptUNode);
-        flags = oldFlags;
-        return start;
-      }
-      else
-      {
-        if (ahead)
-        {
-          cur = cur->next = registerNode(new NFAAcceptUNode);
-          flags = oldFlags;
-          return *end = registerNode(new NFALookAheadUNode(start, pos));
-        }
-        else if (indep)
-        {
-          cur = cur->next = registerNode(new NFAAcceptUNode);
-          flags = oldFlags;
-          return *end = registerNode(new NFAPossessiveQuantifierUNode(this, start, 1, 1));
-        }
-        else // capping or noncapping, it doesnt matter
-        {
-          *end = cur = cur->next = registerNode(new NFAGroupTailUNode(grc));
-          next = quantifyGroup(start, *end, grc);
-          if (next)
-          {
-            start = next;
-            *end = next->next;
-          }
-          flags = oldFlags;
-          return start;
-        }
-      }
-      break;
-    case (wchar_t)'{': // registered pattern
-      cur->next = parseRegisteredWCPattern(&next);
-      if (cur->next) cur = next;
-      break;
-    case (wchar_t)'*':
-    case (wchar_t)'+':
-    case (wchar_t)'?':
-//    case (wchar_t)'}':
-//    case (wchar_t)']':
-      raiseError();
-      break;
-    default:
-      if ((flags & WCPattern::CASE_INSENSITIVE) != 0) next = registerNode(new NFACICharUNode(ch));
-      else                                          next = registerNode(new NFACharUNode(ch));
-      break;
-    }
-    if (next) cur = cur->next = quantify(next);
-  }
-  if (inParen) raiseError();
-  else
-  {
-    if (inOr) cur = cur->next = registerNode(new NFAAcceptUNode);
-    if (end) *end = cur;
-  }
-
-  flags = oldFlags;
-  if (error) return NULL;
-
-  return start;
-}
-
-WCPattern * WCPattern::compile(const bkstring & pattern, const unsigned long mode)
-{
-  WCPattern * p = new WCPattern(pattern);
-  NFAUNode * end;
-
-  p->flags = mode;
-  if ((mode & WCPattern::LITERAL) != 0)
-  {
-    p->head = p->registerNode(new NFAStartUNode);
-    if ((mode & WCPattern::CASE_INSENSITIVE) != 0)  p->head->next = p->registerNode(new NFACIQuoteUNode(pattern));
-    else                                          p->head->next = p->registerNode(new NFAQuoteUNode(pattern));
-    p->head->next->next = p->registerNode(new NFAEndUNode);
-  }
-  else
-  {
-    p->head = p->parse(0, 0, &end);
-    if (!p->head)
-    {
-      delete p;
-      p = NULL;
-    }
-    else
-    {
-      if (!(p->head && p->head->isStartOfInputNode()))
-      {
-        NFAUNode * n = p->registerNode(new NFAStartUNode);
-        n->next = p->head;
-        p->head = n;
-      }
-      end->next = p->registerNode(new NFAEndUNode);
-    }
-  }
-  if (p != NULL)
-  {
-    p->matcher = new WCMatcher(p, L"");
-  }
-
-  return p;
-}
-
-WCPattern * WCPattern::compileAndKeep(const bkstring & pattern, const unsigned long mode)
-{
-  WCPattern * ret = NULL;
-  std::map<bkstring, WCPattern*>::iterator it = compiledWCPatterns.find(pattern);
-
-  if (it != compiledWCPatterns.end())
-  {
-    ret = it->second;
-  }
-  else
-  {
-    ret = compile(pattern, mode);
-    compiledWCPatterns[pattern] = ret;
-  }
-
-  return ret;
-}
-bkstring WCPattern::replace(const bkstring & pattern, const bkstring & str,
-                                     const bkstring & replacementText, const unsigned long mode)
-{
-  bkstring ret;
-  WCPattern * p = WCPattern::compile(pattern, mode);
-  if (p)
-  {
-    ret = p->replace(str, replacementText);
-    delete p;
-  }
-  return ret;
-}
-
-std::vector<bkstring> WCPattern::split(const bkstring & pattern, const bkstring & str, const bool keepEmptys,
-                              const unsigned long limit, const unsigned long mode)
-{
-  std::vector<bkstring> ret;
-  WCPattern * p = WCPattern::compile(pattern, mode);
-  if (p)
-  {
-    ret = p->split(str, keepEmptys, limit);
-    delete p;
-  }
-  return ret;
-}
-
-std::vector<bkstring> WCPattern::findAll(const bkstring & pattern, const bkstring & str, const unsigned long mode)
-{
-  std::vector<bkstring> ret;
-  WCPattern * p = WCPattern::compile(pattern, mode);
-  if (p)
-  {
-    ret = p->findAll(str);
-    delete p;
-  }
-  return ret;
-}
-
-bool WCPattern::matches(const bkstring & pattern, const bkstring & str, const unsigned long mode)
-{
-  bool ret = 0;
-  WCPattern * p = compile(pattern, mode);
-
-  if (p)
-  {
-    ret = p->matches(str);
-    delete p;
-  }
-
-  return ret;
-}
-
-bool WCPattern::registerWCPattern(const bkstring & name, const bkstring & pattern, const unsigned long mode)
-{
-  WCPattern * p = WCPattern::compile(pattern, mode);
-  if (!p) return 0;
-  WCPattern::registeredWCPatterns[name] = std::make_pair(pattern, mode);
-  delete p;
-  return 1;
+	NFAUNode * start, *cur, *next = NULL;
+	CMString t;
+	int grc = groupCount++;
+	bool inv, quo;
+	bool ahead = 0, pos = 0, noncap = 0, indep = 0;
+	unsigned long oldFlags = flags;
+
+	if (inParen)
+	{
+		if (pattern[curInd] == '?')
+		{
+			++curInd;
+			--groupCount;
+			if (pattern[curInd] == ':')   { noncap = 1; ++curInd;     grc = --nonCapGroupCount; }
+			else if (pattern[curInd] == '=')   { ++curInd;     ahead = 1;  pos = 1; }
+			else if (pattern[curInd] == '!')   { ++curInd;     ahead = 1;  pos = 0; }
+			else if (pattern.Mid(curInd, 2) == L"<=")  { curInd += 2;  return parseBehind(1, end); }
+			else if (pattern.Mid(curInd, 2) == L"<!")  { curInd += 2;  return parseBehind(0, end); }
+			else if (pattern[curInd] == '>')   { ++curInd;     indep = 1; }
+			else
+			{
+				bool negate = false, done = false;
+				while (!done)
+				{
+					if (curInd >= pattern.GetLength())
+					{
+						raiseError();
+						return NULL;
+					}
+					else if (negate)
+					{
+						switch (pattern[curInd])
+						{
+						case 'i': flags &= ~WCPattern::CASE_INSENSITIVE;   break;
+						case 'd': flags &= ~WCPattern::UNIX_LINE_MODE;     break;
+						case 'm': flags &= ~WCPattern::MULTILINE_MATCHING; break;
+						case 's': flags &= ~WCPattern::DOT_MATCHES_ALL;    break;
+						case ':': done = true;                             break;
+						case ')':
+							++curInd;
+							*end = registerNode(new NFALookBehindUNode(L"", true));
+							return *end;
+						case '-':
+						default: raiseError(); return NULL;
+						}
+					}
+					else
+					{
+						switch (pattern[curInd])
+						{
+						case 'i': flags |= WCPattern::CASE_INSENSITIVE;    break;
+						case 'd': flags |= WCPattern::UNIX_LINE_MODE;      break;
+						case 'm': flags |= WCPattern::MULTILINE_MATCHING;  break;
+						case 's': flags |= WCPattern::DOT_MATCHES_ALL;     break;
+						case ':': done = true;                             break;
+						case '-': negate = true;                           break;
+						case ')':
+							++curInd;
+							*end = registerNode(new NFALookBehindUNode(L"", true));
+							return *end;
+						default:  raiseError(); return NULL;
+						}
+					}
+					++curInd;
+				}
+				noncap = 1;
+				grc = --nonCapGroupCount;
+			}
+
+			if (noncap) cur = start = registerNode(new NFAGroupHeadUNode(grc));
+			else        cur = start = registerNode(new NFASubStartUNode);
+		}
+		else cur = start = registerNode(new NFAGroupHeadUNode(grc));
+	}
+	else cur = start = registerNode(new NFASubStartUNode);
+	while (curInd < pattern.GetLength())
+	{
+		wchar_t ch = pattern[curInd++];
+
+		next = NULL;
+		if (error) return NULL;
+		switch (ch) {
+		case '^':
+			if ((flags & WCPattern::MULTILINE_MATCHING) != 0) next = registerNode(new NFAStartOfLineUNode);
+			else                                            next = registerNode(new NFAStartOfInputUNode);
+			break;
+		case '$':
+			if ((flags & WCPattern::MULTILINE_MATCHING) != 0) next = registerNode(new NFAEndOfLineUNode);
+			else                                            next = registerNode(new NFAEndOfInputUNode(0));
+			break;
+		case '|':
+			--groupCount;
+			cur->next = registerNode(new NFAAcceptUNode);
+			cur = start = registerNode(new NFAOrUNode(start, parse(inParen, 1)));
+			break;
+		case '\\':
+			if (curInd < pattern.GetLength()) {
+				bool eoi = 0;
+				switch (pattern[curInd]) {
+				case '1':
+				case '2':
+				case '3':
+				case '4':
+				case '5':
+				case '6':
+				case '7':
+				case '8':
+				case '9': next = parseBackref(); break;
+				case 'A': ++curInd; next = registerNode(new NFAStartOfInputUNode);     break;
+				case 'B': ++curInd; next = registerNode(new NFAWordBoundaryUNode(0));  break;
+				case 'b': ++curInd; next = registerNode(new NFAWordBoundaryUNode(1));  break;
+				case 'G': ++curInd; next = registerNode(new NFAEndOfMatchUNode);       break;
+				case 'Z': eoi = 1;
+				case 'z': ++curInd; next = registerNode(new NFAEndOfInputUNode(eoi));  break;
+				default:
+					t = parseEscape(inv, quo);
+					//printf("inv quo classes { %c %c %s }\n", inv ? 't' : 'f', quo ? 't' : 'f', t.c_str());
+					if (!quo) {
+						if (t.GetLength() > 1 || inv) {
+							if ((flags & WCPattern::CASE_INSENSITIVE) != 0) next = registerNode(new NFACIClassUNode(t, inv));
+							else                                            next = registerNode(new NFAClassUNode(t, inv));
+						}
+						else next = registerNode(new NFACharUNode(t[0]));
+					}
+					else next = parseQuote();
+				}
+			}
+			else raiseError();
+			break;
+		case '[':
+			if ((flags & WCPattern::CASE_INSENSITIVE) == 0) {
+				NFAClassUNode * clazz = new NFAClassUNode();
+				CMString s = parseClass();
+				for (int i = 0; i < (int)s.GetLength(); ++i) clazz->vals[s[i]] = 1;
+				next = registerNode(clazz);
+			}
+			else {
+				NFACIClassUNode * clazz = new NFACIClassUNode();
+				CMString s = parseClass();
+				for (int i = 0; i < s.GetLength(); ++i) clazz->vals[to_lower(s[i])] = 1;
+				next = registerNode(clazz);
+			}
+			break;
+		case '.':
+			{
+				bool useN = 1, useR = 1;
+				NFAClassUNode * clazz = new NFAClassUNode(1);
+				if ((flags & WCPattern::UNIX_LINE_MODE) != 0) useR = 0;
+				if ((flags & WCPattern::DOT_MATCHES_ALL) != 0) useN = useR = 0;
+				if (useN) clazz->vals['\n'] = 1;
+				if (useR) clazz->vals['\r'] = 1;
+				next = registerNode(clazz);
+			}
+			break;
+		case '(':
+			{
+				NFAUNode *end, *t1, *t2;
+				t1 = parse(1, 0, &end);
+				if (!t1) raiseError();
+				else if (t1->isGroupHeadNode() && (t2 = quantifyGroup(t1, end, grc)) != NULL) {
+					cur->next = t2;
+					cur = t2->next;
+				}
+				else {
+					cur->next = t1;
+					cur = end;
+				}
+			}
+			break;
+		case ')':
+			if (!inParen) raiseError();
+			else if (inOr)
+			{
+				--curInd;
+				cur = cur->next = registerNode(new NFAAcceptUNode);
+				flags = oldFlags;
+				return start;
+			}
+			else
+			{
+				if (ahead)
+				{
+					cur = cur->next = registerNode(new NFAAcceptUNode);
+					flags = oldFlags;
+					return *end = registerNode(new NFALookAheadUNode(start, pos));
+				}
+				else if (indep)
+				{
+					cur = cur->next = registerNode(new NFAAcceptUNode);
+					flags = oldFlags;
+					return *end = registerNode(new NFAPossessiveQuantifierUNode(this, start, 1, 1));
+				}
+				else // capping or noncapping, it doesnt matter
+				{
+					*end = cur = cur->next = registerNode(new NFAGroupTailUNode(grc));
+					next = quantifyGroup(start, *end, grc);
+					if (next)
+					{
+						start = next;
+						*end = next->next;
+					}
+					flags = oldFlags;
+					return start;
+				}
+			}
+			break;
+		case '{': // registered pattern
+			cur->next = parseRegisteredWCPattern(&next);
+			if (cur->next) cur = next;
+			break;
+		case '*':
+		case '+':
+		case '?':
+			//    case '}':
+			//    case ']':
+			raiseError();
+			break;
+		default:
+			if ((flags & WCPattern::CASE_INSENSITIVE) != 0) next = registerNode(new NFACICharUNode(ch));
+			else                                          next = registerNode(new NFACharUNode(ch));
+			break;
+		}
+		if (next) cur = cur->next = quantify(next);
+	}
+	if (inParen) raiseError();
+	else
+	{
+		if (inOr) cur = cur->next = registerNode(new NFAAcceptUNode);
+		if (end) *end = cur;
+	}
+
+	flags = oldFlags;
+	if (error) return NULL;
+
+	return start;
+}
+
+WCPattern * WCPattern::compile(const CMString & pattern, const unsigned long mode)
+{
+	WCPattern * p = new WCPattern(pattern);
+	NFAUNode * end;
+
+	p->flags = mode;
+	if ((mode & WCPattern::LITERAL) != 0) {
+		p->head = p->registerNode(new NFAStartUNode);
+		if ((mode & WCPattern::CASE_INSENSITIVE) != 0)  p->head->next = p->registerNode(new NFACIQuoteUNode(pattern));
+		else                                          p->head->next = p->registerNode(new NFAQuoteUNode(pattern));
+		p->head->next->next = p->registerNode(new NFAEndUNode);
+	}
+	else {
+		p->head = p->parse(0, 0, &end);
+		if (!p->head) {
+			delete p;
+			p = NULL;
+		}
+		else {
+			if (!(p->head && p->head->isStartOfInputNode())) {
+				NFAUNode * n = p->registerNode(new NFAStartUNode);
+				n->next = p->head;
+				p->head = n;
+			}
+			end->next = p->registerNode(new NFAEndUNode);
+		}
+	}
+
+	if (p != NULL)
+		p->matcher = new WCMatcher(p, L"");
+
+	return p;
+}
+
+WCPattern * WCPattern::compileAndKeep(const CMString & pattern, const unsigned long mode)
+{
+	WCPattern * ret = NULL;
+	std::map<CMString, WCPattern*>::iterator it = compiledWCPatterns.find(pattern);
+	if (it != compiledWCPatterns.end())
+		ret = it->second;
+	else {
+		ret = compile(pattern, mode);
+		compiledWCPatterns[pattern] = ret;
+	}
+
+	return ret;
+}
+CMString WCPattern::replace(const CMString & pattern, const CMString & str,
+	const CMString & replacementText, const unsigned long mode)
+{
+	CMString ret;
+	WCPattern * p = WCPattern::compile(pattern, mode);
+	if (p)
+	{
+		ret = p->replace(str, replacementText);
+		delete p;
+	}
+	return ret;
+}
+
+std::vector<CMString> WCPattern::split(const CMString & pattern, const CMString & str, const bool keepEmptys,
+	const unsigned long limit, const unsigned long mode)
+{
+	std::vector<CMString> ret;
+	WCPattern *p = WCPattern::compile(pattern, mode);
+	if (p) {
+		ret = p->split(str, keepEmptys, limit);
+		delete p;
+	}
+	return ret;
+}
+
+std::vector<CMString> WCPattern::findAll(const CMString & pattern, const CMString & str, const unsigned long mode)
+{
+	std::vector<CMString> ret;
+	WCPattern *p = WCPattern::compile(pattern, mode);
+	if (p) {
+		ret = p->findAll(str);
+		delete p;
+	}
+	return ret;
+}
+
+bool WCPattern::matches(const CMString & pattern, const CMString & str, const unsigned long mode)
+{
+	bool ret = 0;
+	WCPattern * p = compile(pattern, mode);
+
+	if (p)
+	{
+		ret = p->matches(str);
+		delete p;
+	}
+
+	return ret;
+}
+
+bool WCPattern::registerWCPattern(const CMString & name, const CMString & pattern, const unsigned long mode)
+{
+	WCPattern * p = WCPattern::compile(pattern, mode);
+	if (!p) return 0;
+	WCPattern::registeredWCPatterns[name] = std::make_pair(pattern, mode);
+	delete p;
+	return 1;
 }
 
 void WCPattern::unregisterWCPatterns()
 {
-  registeredWCPatterns.clear();
+	registeredWCPatterns.clear();
 }
 void WCPattern::clearWCPatternCache()
 {
-  std::map<bkstring, WCPattern*>::iterator it;
-  for (it = compiledWCPatterns.begin(); it != compiledWCPatterns.end(); ++it)
-  {
-    delete it->second;
-  }
-  compiledWCPatterns.clear();
+	std::map<CMString, WCPattern*>::iterator it;
+	for (it = compiledWCPatterns.begin(); it != compiledWCPatterns.end(); ++it)
+		delete it->second;
+
+	compiledWCPatterns.clear();
 }
 
-std::pair<bkstring, int>  WCPattern::findNthMatch(const bkstring & pattern, const bkstring & str,
-                                         const int matchNum, const unsigned long mode)
+std::pair<CMString, int>  WCPattern::findNthMatch(const CMString & pattern, const CMString & str,
+	const int matchNum, const unsigned long mode)
 {
-  std::pair<bkstring, int> ret;
-  WCPattern * p = WCPattern::compile(pattern, mode);
+	std::pair<CMString, int> ret;
+	WCPattern * p = WCPattern::compile(pattern, mode);
 
-  ret.second = -1;
-  if (p)
-  {
-    int i = -1;
-    p->matcher->setString(str);
-    while (i < matchNum && p->matcher->findNextMatch()) { ++i; }
-    if (i == matchNum && p->matcher->getStartingIndex() >= 0)
-    {
-      ret.first = p->matcher->getGroup(0);
-      ret.second = p->matcher->getStartingIndex();
-    }
-    delete p;
-  }
+	ret.second = -1;
+	if (p)
+	{
+		int i = -1;
+		p->matcher->setString(str);
+		while (i < matchNum && p->matcher->findNextMatch()) { ++i; }
+		if (i == matchNum && p->matcher->getStartingIndex() >= 0)
+		{
+			ret.first = p->matcher->getGroup(0);
+			ret.second = p->matcher->getStartingIndex();
+		}
+		delete p;
+	}
 
-  return ret;
+	return ret;
 }
 
 WCPattern::~WCPattern()
 {
-  /*
-  nodes.clear();
-  if (head) head->findAllNodes(nodes);
-  */
-  if (matcher) delete matcher;
-  for (std::map<NFAUNode*, bool>::iterator it = nodes.begin(); it != nodes.end(); ++it) delete it->first;
+	/*
+	nodes.Empty();
+	if (head) head->findAllNodes(nodes);
+	*/
+	if (matcher) delete matcher;
+	for (std::map<NFAUNode*, bool>::iterator it = nodes.begin(); it != nodes.end(); ++it)
+		delete it->first;
 }
-bkstring WCPattern::replace(const bkstring & str, const bkstring & replacementText)
+CMString WCPattern::replace(const CMString & str, const CMString & replacementText)
 {
-  int li = 0;
-  bkstring ret = L"";
+	int li = 0;
+	CMString ret = L"";
 
-  matcher->setString(str);
-  while (matcher->findNextMatch())
-  {
-    ret += str.substr(li, matcher->getStartingIndex() - li);
-    ret += matcher->replaceWithGroups(replacementText);
-    li = matcher->getEndingIndex();
-  }
-  ret += str.substr(li);
+	matcher->setString(str);
+	while (matcher->findNextMatch())
+	{
+		ret += str.Mid(li, matcher->getStartingIndex() - li);
+		ret += matcher->replaceWithGroups(replacementText);
+		li = matcher->getEndingIndex();
+	}
+	ret += str.Mid(li);
 
-  return ret;
+	return ret;
 }
-std::vector<bkstring> WCPattern::split(const bkstring & str, const bool keepEmptys, const unsigned long limit)
+std::vector<CMString> WCPattern::split(const CMString & str, const bool keepEmptys, const unsigned long limit)
 {
-  unsigned long lim = (limit == 0 ? MAX_QMATCH : limit);
-  int li = 0;
-  std::vector<bkstring> ret;
+	unsigned long lim = (limit == 0 ? MAX_QMATCH : limit);
+	int li = 0;
+	std::vector<CMString> ret;
 
-  matcher->setString(str);
+	matcher->setString(str);
 
-  while (matcher->findNextMatch() && ret.size() < lim)
-  {
-    if (matcher->getStartingIndex() == 0 && keepEmptys) ret.push_back(L"");
-    if ((matcher->getStartingIndex() != matcher->getEndingIndex()) || keepEmptys)
-    {
-      if (li != matcher->getStartingIndex() || keepEmptys)
-      {
-        ret.push_back(str.substr(li, matcher->getStartingIndex() - li));
-      }
-      li = matcher->getEndingIndex();
-    }
-  }
-  if (li < (int)str.size()) ret.push_back(str.substr(li));
+	while (matcher->findNextMatch() && ret.size() < lim)
+	{
+		if (matcher->getStartingIndex() == 0 && keepEmptys) ret.push_back(L"");
+		if ((matcher->getStartingIndex() != matcher->getEndingIndex()) || keepEmptys)
+		{
+			if (li != matcher->getStartingIndex() || keepEmptys)
+			{
+				ret.push_back(str.Mid(li, matcher->getStartingIndex() - li));
+			}
+			li = matcher->getEndingIndex();
+		}
+	}
+	if (li < str.GetLength()) ret.push_back(str.Mid(li));
 
-  return ret;
+	return ret;
 }
-std::vector<bkstring> WCPattern::findAll(const bkstring & str)
+std::vector<CMString> WCPattern::findAll(const CMString & str)
 {
-  matcher->setString(str);
-  return matcher->findAll();
+	matcher->setString(str);
+	return matcher->findAll();
 }
-bool WCPattern::matches(const bkstring & str)
+bool WCPattern::matches(const CMString & str)
 {
-  matcher->setString(str);
-  return matcher->matches();
+	matcher->setString(str);
+	return matcher->matches();
 }
 unsigned long WCPattern::getFlags() const
 {
-  return flags;
+	return flags;
 }
-bkstring WCPattern::getWCPattern() const
+CMString WCPattern::getWCPattern() const
 {
-  return pattern;
+	return pattern;
 }
-WCMatcher * WCPattern::createWCMatcher(const bkstring & str)
+WCMatcher * WCPattern::createWCMatcher(const CMString & str)
 {
-  return new WCMatcher(this, str);
+	return new WCMatcher(this, str);
 }
 
 // NFAUNode
@@ -1196,227 +1133,233 @@ NFAUNode::NFAUNode() { next = NULL; }
 NFAUNode::~NFAUNode() { }
 void NFAUNode::findAllNodes(std::map<NFAUNode*, bool> & soFar)
 {
-  if (soFar.find(this) == soFar.end()) return;
-  soFar[this] = 1;
-  if (next) next->findAllNodes(soFar);
+	if (soFar.find(this) == soFar.end()) return;
+	soFar[this] = 1;
+	if (next) next->findAllNodes(soFar);
 }
 
 // NFACharUNode
 
 NFACharUNode::NFACharUNode(const wchar_t c) { ch = c; }
-int NFACharUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
+int NFACharUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
 {
-  if (curInd < (int)str.size() && str[curInd] == ch) return next->match(str, matcher, curInd + 1);
-  return -1;
+	if (curInd < str.GetLength() && str[curInd] == ch)
+		return next->match(str, matcher, curInd + 1);
+	return -1;
 }
 
 // NFACICharUNode
 
 NFACICharUNode::NFACICharUNode(const wchar_t c) { ch = to_lower(c); }
-int NFACICharUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
+int NFACICharUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
 {
-  if (curInd < (int)str.size() && to_lower(str[curInd]) == ch) return next->match(str, matcher, curInd + 1);
-  return -1;
+	if (curInd < str.GetLength() && to_lower(str[curInd]) == ch)
+		return next->match(str, matcher, curInd + 1);
+	return -1;
 }
 
 // NFAStartUNode
 
 NFAStartUNode::NFAStartUNode() { }
-int NFAStartUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
-{
-  int ret = -1, ci = curInd;
-
-  matcher->starts[0] = curInd;
-  if ((matcher->getFlags() & WCMatcher::MATCH_ENTIRE_STRING) == (unsigned int)WCMatcher::MATCH_ENTIRE_STRING)
-  {
-    if (curInd != 0)
-    {
-      matcher->starts[0] = -1;
-      return -1;
-    }
-    return next->match(str, matcher, 0);
-  }
-  while ((ret = next->match(str, matcher, ci)) == -1 && ci < (int)str.size())
-  {
-    matcher->clearGroups();
-    matcher->starts[0] = ++ci;
-  }
-  if (ret < 0) matcher->starts[0] = -1;
-  return ret;
+int NFAStartUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
+{
+	int ret = -1, ci = curInd;
+
+	matcher->starts[0] = curInd;
+	if ((matcher->getFlags() & WCMatcher::MATCH_ENTIRE_STRING) == (unsigned int)WCMatcher::MATCH_ENTIRE_STRING)
+	{
+		if (curInd != 0)
+		{
+			matcher->starts[0] = -1;
+			return -1;
+		}
+		return next->match(str, matcher, 0);
+	}
+	while ((ret = next->match(str, matcher, ci)) == -1 && ci < str.GetLength())
+	{
+		matcher->clearGroups();
+		matcher->starts[0] = ++ci;
+	}
+	if (ret < 0) matcher->starts[0] = -1;
+	return ret;
 }
 
 // NFAEndUNode
 
 NFAEndUNode::NFAEndUNode() { }
-int NFAEndUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
+int NFAEndUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
 {
-  matcher->ends[0] = curInd;
-  if ((matcher->getFlags() & WCMatcher::MATCH_ENTIRE_STRING) != 0)
-  {
-    if (curInd == (int)str.size()) return curInd;
-    matcher->ends[0] = -1;
-    return -1;
-  }
-  return curInd;
+	matcher->ends[0] = curInd;
+	if ((matcher->getFlags() & WCMatcher::MATCH_ENTIRE_STRING) != 0)
+	{
+		if (curInd == str.GetLength())
+			return curInd;
+		matcher->ends[0] = -1;
+		return -1;
+	}
+	return curInd;
 }
 
 // NFAQuantifierUNode
 
 void NFAQuantifierUNode::findAllNodes(std::map<NFAUNode*, bool> & soFar)
 {
-  inner->findAllNodes(soFar);
-  NFAUNode::findAllNodes(soFar);
+	inner->findAllNodes(soFar);
+	NFAUNode::findAllNodes(soFar);
 }
 NFAQuantifierUNode::NFAQuantifierUNode(WCPattern * pat, NFAUNode * internal, const int minMatch, const int maxMatch)
 {
-  inner = internal;
-  inner->next = pat->registerNode(new NFAAcceptUNode);
-  min = (minMatch < WCPattern::MIN_QMATCH) ? WCPattern::MIN_QMATCH : minMatch;
-  max = (maxMatch > WCPattern::MAX_QMATCH) ? WCPattern::MAX_QMATCH : maxMatch;
+	inner = internal;
+	inner->next = pat->registerNode(new NFAAcceptUNode);
+	min = (minMatch < WCPattern::MIN_QMATCH) ? WCPattern::MIN_QMATCH : minMatch;
+	max = (maxMatch > WCPattern::MAX_QMATCH) ? WCPattern::MAX_QMATCH : maxMatch;
 }
 
-int NFAQuantifierUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
+int NFAQuantifierUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
 {
-  int i0, i1, i2 = 0;
+	int i0, i1, i2 = 0;
 
-  i0 = i1 = curInd;
-  while (i2 < min)
-  {
+	i0 = i1 = curInd;
+	while (i2 < min)
+	{
 
-    ++i2;
-    i1 = inner->match(str, matcher, i0);
-    if (i1 <= i0) return i1; // i1 < i0 means i1 is -1
-    i0 = i1;
-  }
+		++i2;
+		i1 = inner->match(str, matcher, i0);
+		if (i1 <= i0) return i1; // i1 < i0 means i1 is -1
+		i0 = i1;
+	}
 
-  return i1;
+	return i1;
 }
 // NFAGreedyQuantifierUNode
 
 NFAGreedyQuantifierUNode::NFAGreedyQuantifierUNode(WCPattern * pat, NFAUNode * internal, const int minMatch, const int maxMatch)
-                        : NFAQuantifierUNode(pat, internal, minMatch, maxMatch) { }
-int NFAGreedyQuantifierUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
+: NFAQuantifierUNode(pat, internal, minMatch, maxMatch) { }
+int NFAGreedyQuantifierUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
 {
-  int t = NFAQuantifierUNode::match(str, matcher, curInd);
-  if (t != -1) return matchInternal(str, matcher, t, min);
-  return t;
+	int t = NFAQuantifierUNode::match(str, matcher, curInd);
+	if (t != -1) return matchInternal(str, matcher, t, min);
+	return t;
 }
-int NFAGreedyQuantifierUNode::matchInternal(const bkstring & str, WCMatcher * matcher, const int curInd, const int soFar) const
+int NFAGreedyQuantifierUNode::matchInternal(const CMString & str, WCMatcher * matcher, const int curInd, const int soFar) const
 {
-  if (soFar >= max) return next->match(str, matcher, curInd);
+	if (soFar >= max) return next->match(str, matcher, curInd);
 
-  int i, j;
+	int i, j;
 
-  i = inner->match(str, matcher, curInd);
-  if (i != -1)
-  {
-    j = matchInternal(str, matcher, i, soFar + 1);
-    if (j != -1) return j;
-  }
-  return next->match(str, matcher, curInd);
+	i = inner->match(str, matcher, curInd);
+	if (i != -1)
+	{
+		j = matchInternal(str, matcher, i, soFar + 1);
+		if (j != -1) return j;
+	}
+	return next->match(str, matcher, curInd);
 }
 
 // NFALazyQuantifierUNode
 
 NFALazyQuantifierUNode::NFALazyQuantifierUNode(WCPattern * pat, NFAUNode * internal, const int minMatch, const int maxMatch)
-                      : NFAQuantifierUNode(pat, internal, minMatch, maxMatch) { }
-int NFALazyQuantifierUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
-{
-  int i, j, m = NFAQuantifierUNode::match(str, matcher, curInd);
-
-  if (m == -1) return -1;
-
-  for (i = min; i < max; ++i)
-  {
-    j = next->match(str, matcher, m);
-    if (j == -1)
-    {
-      j = inner->match(str, matcher, m);
-      // if j < m, then j is -1, so we bail.
-      // if j == m, then we would just go and call next->match on the same index,
-      // but it already failed trying to match right there, so we know we can
-      // just bail
-      if (j <= m) return -1;
-      m = j;
-    }
-    else return j;
-  }
-  return next->match(str, matcher, m);
+: NFAQuantifierUNode(pat, internal, minMatch, maxMatch) { }
+int NFALazyQuantifierUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
+{
+	int i, j, m = NFAQuantifierUNode::match(str, matcher, curInd);
+
+	if (m == -1) return -1;
+
+	for (i = min; i < max; ++i)
+	{
+		j = next->match(str, matcher, m);
+		if (j == -1)
+		{
+			j = inner->match(str, matcher, m);
+			// if j < m, then j is -1, so we bail.
+			// if j == m, then we would just go and call next->match on the same index,
+			// but it already failed trying to match right there, so we know we can
+			// just bail
+			if (j <= m) return -1;
+			m = j;
+		}
+		else return j;
+	}
+	return next->match(str, matcher, m);
 }
 
 // NFAPossessiveQuantifierUNode
 
 NFAPossessiveQuantifierUNode::NFAPossessiveQuantifierUNode(WCPattern * pat, NFAUNode * internal, const int minMatch, const int maxMatch)
-                            : NFAQuantifierUNode(pat, internal, minMatch, maxMatch) { }
-int NFAPossessiveQuantifierUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
+: NFAQuantifierUNode(pat, internal, minMatch, maxMatch) { }
+int NFAPossessiveQuantifierUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
 {
-  int i, j, m = NFAQuantifierUNode::match(str, matcher, curInd);
+	int i, j, m = NFAQuantifierUNode::match(str, matcher, curInd);
 
-  if (m == -1) return -1;
-  for (i = min; i < max; ++i)
-  {
-    j = inner->match(str, matcher, m);
-    if (j <= m) return next->match(str, matcher, m);
-    m = j;
-  }
-  return next->match(str, matcher, m);
+	if (m == -1) return -1;
+	for (i = min; i < max; ++i)
+	{
+		j = inner->match(str, matcher, m);
+		if (j <= m) return next->match(str, matcher, m);
+		m = j;
+	}
+	return next->match(str, matcher, m);
 }
 
 // NFAAcceptUNode
 
 NFAAcceptUNode::NFAAcceptUNode() { }
-int NFAAcceptUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
+int NFAAcceptUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
 {
-  if (!next) return curInd;
-  else return next->match(str, matcher, curInd);
+	if (!next) return curInd;
+	else return next->match(str, matcher, curInd);
 }
 
 // NFAClassUNode
 
 NFAClassUNode::NFAClassUNode(const bool invert)
 {
-  inv = invert;
+	inv = invert;
 }
-NFAClassUNode::NFAClassUNode(const bkstring & clazz, const bool invert)
+NFAClassUNode::NFAClassUNode(const CMString & clazz, const bool invert)
 {
-  inv = invert;
-  for (int i = 0; i < (int)clazz.size(); ++i) vals[clazz[i]] = 1;
+	inv = invert;
+	for (int i = 0; i < clazz.GetLength(); ++i)
+		vals[clazz[i]] = 1;
 }
-int NFAClassUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
+int NFAClassUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
 {
-  if (curInd < (int)str.size() && ((vals.find(str[curInd]) != vals.end()) ^ inv))
-  {
-    return next->match(str, matcher, curInd + 1);
-  }
-  return -1;
+	if (curInd < str.GetLength() && ((vals.find(str[curInd]) != vals.end()) ^ inv))
+	{
+		return next->match(str, matcher, curInd + 1);
+	}
+	return -1;
 }
 
 // NFACIClassUNode
 
 NFACIClassUNode::NFACIClassUNode(const bool invert)
 {
-  inv = invert;
+	inv = invert;
 }
-NFACIClassUNode::NFACIClassUNode(const bkstring & clazz, const bool invert)
+
+NFACIClassUNode::NFACIClassUNode(const CMString & clazz, const bool invert)
 {
-  inv = invert;
-  for (int i = 0; i < (int)clazz.size(); ++i) vals[to_lower(clazz[i])] = 1;
+	inv = invert;
+	for (int i = 0; i < (int)clazz.GetLength(); ++i)
+		vals[to_lower(clazz[i])] = 1;
 }
-int NFACIClassUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
+
+int NFACIClassUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
 {
-  if (curInd < (int)str.size() && ((vals.find(to_lower(str[curInd])) != vals.end()) ^ inv))
-  {
-    return next->match(str, matcher, curInd + 1);
-  }
-  return -1;
+	if (curInd < str.GetLength() && ((vals.find(to_lower(str[curInd])) != vals.end()) ^ inv))
+		return next->match(str, matcher, curInd + 1);
+
+	return -1;
 }
 
 // NFASubStartUNode
 
 NFASubStartUNode::NFASubStartUNode() { }
-int NFASubStartUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
+int NFASubStartUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
 {
-  return next->match(str, matcher, curInd);
+	return next->match(str, matcher, curInd);
 }
 
 // NFAOrUNode
@@ -1424,39 +1367,39 @@ int NFASubStartUNode::match(const bkstring & str, WCMatcher * matcher, const int
 NFAOrUNode::NFAOrUNode(NFAUNode * first, NFAUNode * second) : one(first), two(second) { }
 void NFAOrUNode::findAllNodes(std::map<NFAUNode*, bool> & soFar)
 {
-  if (one) one->findAllNodes(soFar);
-  if (two) two->findAllNodes(soFar);
-  NFAUNode::findAllNodes(soFar);
+	if (one) one->findAllNodes(soFar);
+	if (two) two->findAllNodes(soFar);
+	NFAUNode::findAllNodes(soFar);
 }
-int NFAOrUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
+int NFAOrUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
 {
-  int ci = one->match(str, matcher, curInd);
+	int ci = one->match(str, matcher, curInd);
 
-  if (ci != -1) ci = next->match(str, matcher, ci);
-  if (ci != -1) return ci;
-  if (ci == -1) ci = two->match(str, matcher, curInd);
-  if (ci != -1) ci = next->match(str, matcher, ci);
-  return ci;
+	if (ci != -1) ci = next->match(str, matcher, ci);
+	if (ci != -1) return ci;
+	if (ci == -1) ci = two->match(str, matcher, curInd);
+	if (ci != -1) ci = next->match(str, matcher, ci);
+	return ci;
 }
 
 // NFAQuoteUNode
 
-NFAQuoteUNode::NFAQuoteUNode(const bkstring & quoted) : qStr(quoted) { }
-int NFAQuoteUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
+NFAQuoteUNode::NFAQuoteUNode(const CMString & quoted) : qStr(quoted) { }
+int NFAQuoteUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
 {
-  if (curInd + qStr.size() > str.size())       return -1;
-  if (str.substr(curInd, qStr.size()) != qStr) return -1;
-  return next->match(str, matcher, curInd + (int)qStr.size());
+	if (curInd + qStr.GetLength() > str.GetLength()) return -1;
+	if (str.Mid(curInd, qStr.GetLength()) != qStr) return -1;
+	return next->match(str, matcher, curInd + qStr.GetLength());
 }
 
 // NFACIQuoteUNode
 
-NFACIQuoteUNode::NFACIQuoteUNode(const bkstring & quoted) : qStr(quoted) { }
-int NFACIQuoteUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
+NFACIQuoteUNode::NFACIQuoteUNode(const CMString & quoted) : qStr(quoted) { }
+int NFACIQuoteUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
 {
-  if (curInd + qStr.size() > str.size()) return -1;
-  if (str_icmp(str.substr(curInd, qStr.size()).c_str(),  qStr.c_str())) return -1;
-  return next->match(str, matcher, (int)qStr.size());
+	if (curInd + qStr.GetLength() > str.GetLength()) return -1;
+	if (str_icmp(str.Mid(curInd, qStr.GetLength()).c_str(), qStr.c_str())) return -1;
+	return next->match(str, matcher, qStr.GetLength());
 }
 
 // NFALookAheadUNode
@@ -1464,267 +1407,268 @@ int NFACIQuoteUNode::match(const bkstring & str, WCMatcher * matcher, const int
 NFALookAheadUNode::NFALookAheadUNode(NFAUNode * internal, const bool positive) : NFAUNode(), pos(positive), inner(internal) { }
 void NFALookAheadUNode::findAllNodes(std::map<NFAUNode*, bool> & soFar)
 {
-  if (inner) inner->findAllNodes(soFar);
-  NFAUNode::findAllNodes(soFar);
+	if (inner) inner->findAllNodes(soFar);
+	NFAUNode::findAllNodes(soFar);
 }
-int NFALookAheadUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
+int NFALookAheadUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
 {
-  return ((inner->match(str, matcher, curInd) == -1) ^ pos) ? next->match(str, matcher, curInd) : -1;
+	return ((inner->match(str, matcher, curInd) == -1) ^ pos) ? next->match(str, matcher, curInd) : -1;
 }
 
 // NFALookBehindUNode
 
-NFALookBehindUNode::NFALookBehindUNode(const bkstring & str, const bool positive) : pos(positive), mStr(str) { }
-int NFALookBehindUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
-{
-  if (pos)
-  {
-    if (curInd < (int)mStr.size()) return -1;
-    if (str.substr(curInd - mStr.size(), mStr.size()) == mStr) return next->match(str, matcher, curInd);
-  }
-  else
-  {
-    if (curInd < (int)mStr.size()) return next->match(str, matcher, curInd);
-    if (str.substr(curInd - mStr.size(), mStr.size()) == mStr) return -1;
-     return next->match(str, matcher, curInd);
-  }
-  return -1;
+NFALookBehindUNode::NFALookBehindUNode(const CMString & str, const bool positive) : pos(positive), mStr(str) { }
+int NFALookBehindUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
+{
+	if (pos) {
+		if (curInd < mStr.GetLength())
+			return -1;
+		if (str.Mid(curInd - mStr.GetLength(), mStr.GetLength()) == mStr)
+			return next->match(str, matcher, curInd);
+	}
+	else {
+		if (curInd < mStr.GetLength())
+			return next->match(str, matcher, curInd);
+		if (str.Mid(curInd - mStr.GetLength(), mStr.GetLength()) == mStr)
+			return -1;
+		return next->match(str, matcher, curInd);
+	}
+	return -1;
 }
 
 // NFAStartOfLineUNode
 
 NFAStartOfLineUNode::NFAStartOfLineUNode() { }
-int NFAStartOfLineUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
+int NFAStartOfLineUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
 {
-  if (curInd == 0 || str[curInd - 1] == (wchar_t)'\n' || str[curInd - 1] == (wchar_t)'\r')
-  {
-    return next->match(str, matcher, curInd);
-  }
-  return -1;
+	if (curInd == 0 || str[curInd - 1] == '\n' || str[curInd - 1] == '\r')
+	{
+		return next->match(str, matcher, curInd);
+	}
+	return -1;
 }
 
 // NFAEndOfLineUNode
 
 NFAEndOfLineUNode::NFAEndOfLineUNode() { }
-int NFAEndOfLineUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
+int NFAEndOfLineUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
 {
-  if (curInd >= (int)str.size() || str[curInd] == (wchar_t)'\n' || str[curInd] == (wchar_t)'\r')
-  {
-    return next->match(str, matcher, curInd);
-  }
-  return -1;
+	if (curInd >= str.GetLength() || str[curInd] == '\n' || str[curInd] == '\r')
+		return next->match(str, matcher, curInd);
+
+	return -1;
 }
 
 // NFAReferenceUNode
 
 NFAReferenceUNode::NFAReferenceUNode(const int groupIndex) : gi(groupIndex) { }
-int NFAReferenceUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
+int NFAReferenceUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
 {
-  int len = matcher->ends[gi] - matcher->starts[gi];
-  int ni = -1;
-  if      (gi < 1 || matcher->ends[gi] < matcher->starts[gi] || len == 0)             ni = curInd;
-  else if (curInd + len > (int)str.size())                                            return -1;
-  else if (str.substr(curInd, len) != str.substr(matcher->starts[gi], len))  return -1;
-  else                                                                                ni = curInd + len;
+	int len = matcher->ends[gi] - matcher->starts[gi];
+	int ni = -1;
+	if (gi < 1 || matcher->ends[gi] < matcher->starts[gi] || len == 0)   ni = curInd;
+	else if (curInd + len > (int)str.GetLength())                        return -1;
+	else if (str.Mid(curInd, len) != str.Mid(matcher->starts[gi], len))  return -1;
+	else                                                                 ni = curInd + len;
 
-  return next->match(str, matcher, ni);
+	return next->match(str, matcher, ni);
 }
 
 // NFAStartOfInputUNode
 
 NFAStartOfInputUNode::NFAStartOfInputUNode() { }
-int NFAStartOfInputUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
+int NFAStartOfInputUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
 {
-  if (curInd == 0) return next->match(str, matcher, curInd);
-  return -1;
+	if (curInd == 0) return next->match(str, matcher, curInd);
+	return -1;
 }
 
 // NFAEndOfInputUNode
 
 NFAEndOfInputUNode::NFAEndOfInputUNode(const bool lookForTerm) : term(lookForTerm) { }
-int NFAEndOfInputUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
-{
-  int len = (int)str.size();
-  if      (curInd == len) return next->match(str, matcher, curInd);
-  else if (term)
-  {
-    if      (curInd == len - 1 && (str[curInd] == (wchar_t)'\r' || str[curInd] == (wchar_t)'\n'))
-    {
-      return next->match(str, matcher, curInd);
-    }
-    else if (curInd == len - 2 && str.substr(curInd, 2) == L"\r\n")
-    {
-      return next->match(str, matcher, curInd);
-    }
-  }
-  return -1;
+int NFAEndOfInputUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
+{
+	int len = str.GetLength();
+	if (curInd == len) return next->match(str, matcher, curInd);
+	else if (term)
+	{
+		if (curInd == len - 1 && (str[curInd] == '\r' || str[curInd] == '\n'))
+		{
+			return next->match(str, matcher, curInd);
+		}
+		else if (curInd == len - 2 && str.Mid(curInd, 2) == L"\r\n")
+		{
+			return next->match(str, matcher, curInd);
+		}
+	}
+	return -1;
 }
 
 // NFAWordBoundaryUNode
 
 NFAWordBoundaryUNode::NFAWordBoundaryUNode(const bool positive) : pos(positive) { }
-int NFAWordBoundaryUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
+int NFAWordBoundaryUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
 {
-  int len = (int)str.size();
+	int len = str.GetLength();
 
-  wchar_t c1 = (curInd - 1 < len && curInd > 0) ? str[curInd - 1] : '\n';
-  wchar_t c2 = (curInd     < len) ? str[curInd    ] : '\n';
+	wchar_t c1 = (curInd - 1 < len && curInd > 0) ? str[curInd - 1] : '\n';
+	wchar_t c2 = (curInd < len) ? str[curInd] : '\n';
 
-  if      (curInd == len) return next->match(str, matcher, curInd);
-  bool ok = is_alpha(c1) != is_alpha(c2);
-  if (ok && pos) return next->match(str, matcher, curInd);
-  return -1;
+	if (curInd == len) return next->match(str, matcher, curInd);
+	bool ok = is_alpha(c1) != is_alpha(c2);
+	if (ok && pos) return next->match(str, matcher, curInd);
+	return -1;
 }
 
 // NFAEndOfMatchUNode
 
 NFAEndOfMatchUNode::NFAEndOfMatchUNode() { }
-int NFAEndOfMatchUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
+int NFAEndOfMatchUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
 {
-  if (curInd == matcher->lm) return next->match(str, matcher, curInd);
-  return -1;
+	if (curInd == matcher->lm) return next->match(str, matcher, curInd);
+	return -1;
 }
 
 // NFAGroupHeadUNode
 
 NFAGroupHeadUNode::NFAGroupHeadUNode(const int groupIndex) : gi(groupIndex) { }
-int NFAGroupHeadUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
+int NFAGroupHeadUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
 {
-  int ret, o = matcher->starts[gi];
+	int ret, o = matcher->starts[gi];
 
-  matcher->starts[gi] = curInd;
-  ret = next->match(str, matcher, curInd);
-  if (ret < 0) matcher->starts[gi] = o;
+	matcher->starts[gi] = curInd;
+	ret = next->match(str, matcher, curInd);
+	if (ret < 0) matcher->starts[gi] = o;
 
-  return ret;
+	return ret;
 }
 
 // NFAGroupTailUNode
 
 NFAGroupTailUNode::NFAGroupTailUNode(const int groupIndex) : gi(groupIndex) { }
-int NFAGroupTailUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
+int NFAGroupTailUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
 {
-  int ret, o = matcher->ends[gi];
+	int ret, o = matcher->ends[gi];
 
-  matcher->ends[gi] = curInd;
-  ret = next->match(str, matcher, curInd);
-  if (ret < 0) matcher->ends[gi] = o;
+	matcher->ends[gi] = curInd;
+	ret = next->match(str, matcher, curInd);
+	if (ret < 0) matcher->ends[gi] = o;
 
-  return ret;
+	return ret;
 }
 
 // NFAGroupLoopPrologueUNode
 
 NFAGroupLoopPrologueUNode::NFAGroupLoopPrologueUNode(const int groupIndex) : gi(groupIndex) { }
-int NFAGroupLoopPrologueUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
+int NFAGroupLoopPrologueUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
 {
-  int ret, o1 = matcher->groups[gi], o2 = matcher->groupPos[gi], o3 = matcher->groupIndeces[gi];
+	int ret, o1 = matcher->groups[gi], o2 = matcher->groupPos[gi], o3 = matcher->groupIndeces[gi];
 
-  matcher->groups[gi] = 0;
-  matcher->groupPos[gi] = 0;
-  matcher->groupIndeces[gi] = -1;
-  ret = next->match(str, matcher, curInd);
-  if (ret < 0)
-  {
-    matcher->groups[gi] = o1;
-    matcher->groupPos[gi] = o2;
-    matcher->groupIndeces[gi] = o3;
-  }
+	matcher->groups[gi] = 0;
+	matcher->groupPos[gi] = 0;
+	matcher->groupIndeces[gi] = -1;
+	ret = next->match(str, matcher, curInd);
+	if (ret < 0)
+	{
+		matcher->groups[gi] = o1;
+		matcher->groupPos[gi] = o2;
+		matcher->groupIndeces[gi] = o3;
+	}
 
-  return ret;
+	return ret;
 }
 
 // NFAGroupLoopUNode
 
 NFAGroupLoopUNode::NFAGroupLoopUNode(NFAUNode * internal, const int minMatch, const int maxMatch,
-                                   const int groupIndex, const int matchType)
+	const int groupIndex, const int matchType)
 {
-  inner = internal;
-  min = minMatch;
-  max = maxMatch;
-  gi = groupIndex;
-  type = matchType;
+	inner = internal;
+	min = minMatch;
+	max = maxMatch;
+	gi = groupIndex;
+	type = matchType;
 }
 void NFAGroupLoopUNode::findAllNodes(std::map<NFAUNode*, bool> & soFar)
 {
-  if (inner) inner->findAllNodes(soFar);
-  NFAUNode::findAllNodes(soFar);
-}
-int NFAGroupLoopUNode::match(const bkstring & str, WCMatcher * matcher, const int curInd) const
-{
-  bool b = (curInd > matcher->groupIndeces[gi]);
-
-  if (b && matcher->groups[gi] < min)
-  {
-    ++matcher->groups[gi];
-    int o = matcher->groupIndeces[gi];
-    matcher->groupIndeces[gi] = curInd;
-    int ret = inner->match(str, matcher, curInd);
-    if (ret < 0)
-    {
-      matcher->groupIndeces[gi] = o;
-      --matcher->groups[gi];
-    }
-    return ret;
-  }
-  else if (!b || matcher->groups[gi] >= max)
-  {
-    return next->match(str, matcher, curInd);
-  }
-  else
-  {
-    switch (type)
-    {
-    case 0: return matchGreedy(str, matcher, curInd);
-    case 1: return matchLazy(str, matcher, curInd);
-    case 2: return matchPossessive(str, matcher, curInd);
-    }
-  }
-  return -1;
-}
-int NFAGroupLoopUNode::matchGreedy(const bkstring & str, WCMatcher * matcher, const int curInd) const
-{
-  int o = matcher->groupIndeces[gi];            // save our info for backtracking
-  matcher->groupIndeces[gi] = curInd;           // move along
-  ++matcher->groups[gi];
-  int ret = inner->match(str, matcher, curInd); // match internally
-  if (ret < 0)
-  {                                             // if we failed, then restore info and match next
-    --matcher->groups[gi];
-    matcher->groupIndeces[gi] = o;
-    ret = next->match(str, matcher, curInd);
-  }
-  return ret;
-}
-int NFAGroupLoopUNode::matchLazy(const bkstring & str, WCMatcher * matcher, const int curInd) const
-{
-  int ret = next->match(str, matcher, curInd);  // be lazy, just go on
-  if (ret < 0)
-  {
-    int o = matcher->groupIndeces[gi];          // save info for backtracking
-    matcher->groupIndeces[gi] = curInd;         // advance our position
-    ++matcher->groups[gi];
-    ret = inner->match(str, matcher, curInd);   // match our internal stuff
-    if (ret < 0)                                // if we failed, then restore the info
-    {
-      --matcher->groups[gi];
-      matcher->groupIndeces[gi] = o;
-    }
-  }
-  return ret;
-}
-int NFAGroupLoopUNode::matchPossessive(const bkstring & str, WCMatcher * matcher, const int curInd) const
-{
-  int o = matcher->groupIndeces[gi];            // save info for backtracking
-  matcher->groupPos[gi] = matcher->groups[gi];  // set a flag stating we have matcher at least this much
-  matcher->groupIndeces[gi] = curInd;           // move along
-  ++matcher->groups[gi];
-  int ret = inner->match(str, matcher, curInd); // try and match again
-  if (ret < 0)
-  {                                             // if we fail, back off, but to an extent
-    --matcher->groups[gi];
-    matcher->groupIndeces[gi] = o;
-    if (matcher->groups[gi] == matcher->groupPos[gi]) ret = next->match(str, matcher, curInd);
-  }
-  return ret;
-}
\ No newline at end of file
+	if (inner) inner->findAllNodes(soFar);
+	NFAUNode::findAllNodes(soFar);
+}
+int NFAGroupLoopUNode::match(const CMString & str, WCMatcher * matcher, const int curInd) const
+{
+	bool b = (curInd > matcher->groupIndeces[gi]);
+
+	if (b && matcher->groups[gi] < min)
+	{
+		++matcher->groups[gi];
+		int o = matcher->groupIndeces[gi];
+		matcher->groupIndeces[gi] = curInd;
+		int ret = inner->match(str, matcher, curInd);
+		if (ret < 0)
+		{
+			matcher->groupIndeces[gi] = o;
+			--matcher->groups[gi];
+		}
+		return ret;
+	}
+	else if (!b || matcher->groups[gi] >= max)
+	{
+		return next->match(str, matcher, curInd);
+	}
+	else
+	{
+		switch (type)
+		{
+		case 0: return matchGreedy(str, matcher, curInd);
+		case 1: return matchLazy(str, matcher, curInd);
+		case 2: return matchPossessive(str, matcher, curInd);
+		}
+	}
+	return -1;
+}
+int NFAGroupLoopUNode::matchGreedy(const CMString & str, WCMatcher * matcher, const int curInd) const
+{
+	int o = matcher->groupIndeces[gi];            // save our info for backtracking
+	matcher->groupIndeces[gi] = curInd;           // move along
+	++matcher->groups[gi];
+	int ret = inner->match(str, matcher, curInd); // match internally
+	if (ret < 0)
+	{                                             // if we failed, then restore info and match next
+		--matcher->groups[gi];
+		matcher->groupIndeces[gi] = o;
+		ret = next->match(str, matcher, curInd);
+	}
+	return ret;
+}
+int NFAGroupLoopUNode::matchLazy(const CMString & str, WCMatcher * matcher, const int curInd) const
+{
+	int ret = next->match(str, matcher, curInd);  // be lazy, just go on
+	if (ret < 0)
+	{
+		int o = matcher->groupIndeces[gi];          // save info for backtracking
+		matcher->groupIndeces[gi] = curInd;         // advance our position
+		++matcher->groups[gi];
+		ret = inner->match(str, matcher, curInd);   // match our internal stuff
+		if (ret < 0)                                // if we failed, then restore the info
+		{
+			--matcher->groups[gi];
+			matcher->groupIndeces[gi] = o;
+		}
+	}
+	return ret;
+}
+int NFAGroupLoopUNode::matchPossessive(const CMString & str, WCMatcher * matcher, const int curInd) const
+{
+	int o = matcher->groupIndeces[gi];            // save info for backtracking
+	matcher->groupPos[gi] = matcher->groups[gi];  // set a flag stating we have matcher at least this much
+	matcher->groupIndeces[gi] = curInd;           // move along
+	++matcher->groups[gi];
+	int ret = inner->match(str, matcher, curInd); // try and match again
+	if (ret < 0)
+	{                                             // if we fail, back off, but to an extent
+		--matcher->groups[gi];
+		matcher->groupIndeces[gi] = o;
+		if (matcher->groups[gi] == matcher->groupPos[gi]) ret = next->match(str, matcher, curInd);
+	}
+	return ret;
+}
diff --git a/plugins/SmileyAdd/src/regexp/WCPattern.h b/plugins/SmileyAdd/src/regexp/WCPattern.h
index 143eff7eb7..e3455e8b31 100644
--- a/plugins/SmileyAdd/src/regexp/WCPattern.h
+++ b/plugins/SmileyAdd/src/regexp/WCPattern.h
@@ -771,7 +771,7 @@ class NFAQuantifierUNode;
 
    <h4> Backslashes, escapes, and quoting </h4>
 
-   <p> The backslash character (<tt>(wchar_t)'\'</tt>) serves to introduce escaped
+   <p> The backslash character (<tt>'\'</tt>) serves to introduce escaped
    constructs, as defined in the table above, as well as to quote characters
    that otherwise would be interpreted as unescaped constructs.  Thus the
    expression <tt>\\</tt> matches a single backslash and <tt>\{</tt> matches a
@@ -963,691 +963,691 @@ class NFAQuantifierUNode;
  */
 class WCPattern
 {
-  friend class WCMatcher;
-  friend class NFAUNode;
-  friend class NFAQuantifierUNode;
-  private:
-    /**
-      This constructor should not be called directly. Those wishing to use the
-      WCPattern class should instead use the {@link compile compile} method.
-
-      @param rhs The pattern to compile
-      @memo Creates a new pattern from the regular expression in <code>rhs</code>.
-     */
-    WCPattern(const bkstring & rhs);
-  protected:
-    /**
-      This currently is not used, so don't try to do anything with it.
-      @memo Holds all the compiled patterns for quick access.
-     */
-    static std::map<bkstring, WCPattern *> compiledWCPatterns;
-    /**
-      Holds all of the registered patterns as strings. Due to certain problems
-      with compilation of patterns, especially with capturing groups, this seemed
-      to be the best way to do it.
-     */
-    static std::map<bkstring, std::pair<bkstring, unsigned long> > registeredWCPatterns;
-  protected:
-    /**
-      Holds all the NFA nodes used. This makes deletion of a pattern, as well as
-      clean-up from an unsuccessful compile much easier and faster.
-     */
-    std::map<NFAUNode*, bool> nodes;
-    /**
-      Used when methods like split are called. The matcher class uses a lot of
-      dynamic memeory, so having an instance increases speedup of certain
-      operations.
-     */
-    WCMatcher * matcher;
-    /**
-      The front node of the NFA.
-     */
-    NFAUNode * head;
-    /**
-      The actual regular expression we rerpesent
-      */
-    bkstring pattern;
-    /**
-      Flag used during compilation. Once the pattern is successfully compiled,
-      <code>error</code> is no longer used.
-     */
-    bool error;
-    /**
-      Used during compilation to keep track of the current index into
-      <code>{@link pattern pattern}<code>.  Once the pattern is successfully
-      compiled, <code>error</code> is no longer used.
-     */
-    int curInd;
-    /**
-      The number of capture groups this contains.
-     */
-    int groupCount;
-    /**
-      The number of non-capture groups this contains.
-     */
-    int nonCapGroupCount;
-    /**
-      The flags specified when this was compiled.
-     */
-    unsigned long flags;
-  protected:
-    /**
-      Raises an error during compilation. Compilation will cease at that point
-      and compile will return <code>NULL</code>.
-     */
-    void raiseError();
-    /**
-      Convenience function for registering a node in <code>nodes</code>.
-      @param node The node to register
-      @return The registered node
-     */
-    NFAUNode * registerNode(NFAUNode * node);
-
-    /**
-      Calculates the union of two strings. This function will first sort the
-      strings and then use a simple selection algorithm to find the union.
-      @param s1 The first "class" to union
-      @param s2 The second "class" to union
-      @return A new string containing all unique characters. Each character
-              must have appeared in one or both of <code>s1</code> and
-              <code>s2</code>.
-     */
-    bkstring classUnion      (bkstring s1, bkstring s2)  const;
-    /**
-      Calculates the intersection of two strings. This function will first sort
-      the strings and then use a simple selection algorithm to find the
-      intersection.
-      @param s1 The first "class" to intersect
-      @param s2 The second "class" to intersect
-      @return A new string containing all unique characters. Each character
-              must have appeared both <code>s1</code> and <code>s2</code>.
-     */
-    bkstring classIntersect  (bkstring s1, bkstring s2)  const;
-    /**
-      Calculates the negation of a string. The negation is the set of all
-      characters between <code>\x00</code> and <code>\xFF</code> not
-      contained in <code>s1</code>.
-      @param s1 The "class" to be negated.
-      @param s2 The second "class" to intersect
-      @return A new string containing all unique characters. Each character
-              must have appeared both <code>s1</code> and <code>s2</code>.
-     */
-    bkstring classNegate     (bkstring s1)                  const;
-    /**
-      Creates a new "class" representing the range from <code>low</code> thru
-      <code>hi</code>. This function will wrap if <code>low</code> &gt;
-      <code>hi</code>. This is a feature, not a buf. Sometimes it is useful
-      to be able to say [\x70-\x10] instead of [\x70-\x7F\x00-\x10].
-      @param low The beginning character
-      @param hi  The ending character
-      @return A new string containing all the characters from low thru hi.
-     */
-    bkstring classCreateRange(wchar_t low,       wchar_t hi)         const;
-
-    /**
-      Extracts a decimal number from the substring of member-variable
-      <code>{@link pattern pattern}<code> starting at <code>start</code> and
-      ending at <code>end</code>.
-      @param start The starting index in <code>{@link pattern pattern}<code>
-      @param end The last index in <code>{@link pattern pattern}<code>
-      @return The decimal number in <code>{@link pattern pattern}<code>
-     */
-    int getInt(int start, int end);
-    /**
-      Parses a <code>{n,m}</code> string out of the member-variable
-      <code>{@link pattern pattern}<code> stores the result in <code>sNum</code>
-      and <code>eNum</code>.
-      @param sNum Output parameter. The minimum number of matches required
-                  by the curly quantifier are stored here.
-      @param eNum Output parameter. The maximum number of matches allowed
-                  by the curly quantifier are stored here.
-      @return Success/Failure. Fails when the curly does not have the proper
-              syntax
-     */
-    bool quantifyCurly(int & sNum, int & eNum);
-    /**
-      Tries to quantify the currently parsed group. If the group being parsed
-      is indeed quantified in the member-variable
-      <code>{@link pattern pattern}<code>, then the NFA is modified accordingly.
-      @param start  The starting node of the current group being parsed
-      @param stop   The ending node of the current group being parsed
-      @param gn     The group number of the current group being parsed
-      @return       The node representing the starting node of the group. If the
-                    group becomes quantified, then this node is not necessarily
-                    a GroupHead node.
-     */
-    NFAUNode * quantifyGroup(NFAUNode * start, NFAUNode * stop, const int gn);
-
-    /**
-      Tries to quantify the last parsed expression. If the character was indeed
-      quantified, then the NFA is modified accordingly.
-      @param newNode The recently created expression node
-      @return The node representing the last parsed expression. If the
-              expression was quantified, <code>return value != newNode</code>
-     */
-    NFAUNode * quantify(NFAUNode * newNode);
-    /**
-      Parses the current class being examined in
-      <code>{@link pattern pattern}</code>.
-      @return A string of unique characters contained in the current class being
-              parsed
-     */
-    bkstring parseClass();
-    /**
-      Parses the current POSIX class being examined in
-      <code>{@link pattern pattern}</code>.
-      @return A string of unique characters representing the POSIX class being
-              parsed
-     */
-    bkstring parsePosix();
-    /**
-      Returns a string containing the octal character being parsed
-      @return The string contained the octal value being parsed
-     */
-    bkstring parseOctal();
-    /**
-      Returns a string containing the hex character being parsed
-      @return The string contained the hex value being parsed
-     */
-    bkstring parseHex();
-    /**
-      Returns a new node representing the back reference being parsed
-      @return The new node representing the back reference being parsed
-     */
-    NFAUNode *   parseBackref();
-    /**
-      Parses the escape sequence currently being examined. Determines if the
-      escape sequence is a class, a single character, or the beginning of a
-      quotation sequence.
-      @param inv Output parameter. Whether or not to invert the returned class
-      @param quo Output parameter. Whether or not this sequence starts a
-                 quotation.
-      @return The characters represented by the class
-     */
-    bkstring parseEscape(bool & inv, bool & quo);
-    /**
-      Parses a supposed registered pattern currently under compilation. If the
-      sequence of characters does point to a registered pattern, then the
-      registered pattern is appended to <code>*end<code>. The registered pattern
-      is parsed with the current compilation flags.
-      @param end The ending node of the thus-far compiled pattern
-      @return The new end node of the current pattern
-     */
-    NFAUNode * parseRegisteredWCPattern(NFAUNode ** end);
-    /**
-      Parses a lookbehind expression. Appends the necessary nodes
-      <code>*end</code>.
-      @param pos Positive or negative look behind
-      @param end The ending node of the current pattern
-      @return The new end node of the current pattern
-     */
-    NFAUNode * parseBehind(const bool pos, NFAUNode ** end);
-    /**
-      Parses the current expression and tacks on nodes until a \E is found.
-      @return The end of the current pattern
-     */
-    NFAUNode * parseQuote();
-    /**
-      Parses <code>{@link pattern pattern}</code>. This function is called
-      recursively when an or (<code>|</code>) or a group is encountered.
-      @param inParen Are we currently parsing inside a group
-      @param inOr Are we currently parsing one side of an or (<code>|</code>)
-      @param end The end of the current expression
-      @return The starting node of the NFA constructed from this parse
-     */
-    NFAUNode * parse(const bool inParen = 0, const bool inOr = 0, NFAUNode ** end = NULL);
-  public:
-    /// We should match regardless of case
-    const static unsigned long CASE_INSENSITIVE;
-    /// We are implicitly quoted
-    const static unsigned long LITERAL;
-    /// @memo We should treat a <code><b>.</b></code> as [\x00-\x7F]
-    const static unsigned long DOT_MATCHES_ALL;
-    /** <code>^</code> and <code>$</code> should anchor to the beginning and
-        ending of lines, not all input
-     */
-    const static unsigned long MULTILINE_MATCHING;
-    /** When enabled, only instances of <code>\n</codes> are recognized as
-        line terminators
-     */
-    const static unsigned long UNIX_LINE_MODE;
-    /// The absolute minimum number of matches a quantifier can match (0)
-    const static int MIN_QMATCH;
-    /// The absolute maximum number of matches a quantifier can match (0x7FFFFFFF)
-    const static int MAX_QMATCH;
-  public:
-    /**
-      Call this function to compile a regular expression into a
-      <code>WCPattern</code> object. Special values can be assigned to
-      <code>mode</code> when certain non-standard behaviors are expected from
-      the <code>WCPattern</code> object.
-      @param pattern The regular expression to compile
-      @param mode    A bitwise or of flags signalling what special behaviors are
-                     wanted from this <code>WCPattern</code> object
-      @return If successful, <code>compile</code> returns a <code>WCPattern</code>
-              pointer. Upon failure, <code>compile</code> returns
-              <code>NULL</code>
-     */
-    static WCPattern                    * compile        (const bkstring & pattern,
-                                                        const unsigned long mode = 0);
-    /**
-      Dont use this function. This function will compile a pattern, and cache
-      the result. This will eventually be used as an optimization when people
-      just want to call static methods using the same pattern over and over
-      instead of first compiling the pattern and then using the compiled
-      instance for matching.
-      @param pattern The regular expression to compile
-      @param mode    A bitwise or of flags signalling what special behaviors are
-                     wanted from this <code>WCPattern</code> object
-      @return If successful, <code>compileAndKeep</code> returns a
-              <code>WCPattern</code> pointer. Upon failure, <code>compile</code>
-              returns <code>NULL</code>.
-     */
-    static WCPattern                    * compileAndKeep (const bkstring & pattern,
-                                                        const unsigned long mode = 0);
-
-    /**
-      Searches through <code>replace</code> and replaces all substrings matched
-      by <code>pattern</code> with <code>str</code>. <code>str</code> may
-      contain backreferences (e.g. <code>\1</code>) to capture groups. A typical
-      invocation looks like:
-      <p>
-      <code>
-      WCPattern::replace(L"(a+)b(c+)", L"abcccbbabcbabc", L"\\2b\\1");
-      </code>
-      <p>
-      which would replace <code>abcccbbabcbabc</code> with
-      <code>cccbabbcbabcba</code>.
-      @param pattern          The regular expression
-      @param str              The replacement text
-      @param replacementText  The string in which to perform replacements
-      @param mode             The special mode requested of the <code>WCPattern</code>
-                              during the replacement process
-      @return The text with the replacement string substituted where necessary
-     */
-    static bkstring                  replace       (const bkstring & pattern,
-                                                        const bkstring & str,
-                                                        const bkstring & replacementText,
-                                                        const unsigned long mode = 0);
-
-    /**
-      Splits the specified string over occurrences of the specified pattern.
-      Empty strings can be optionally ignored. The number of strings returned is
-      configurable. A typical invocation looks like:
-      <p>
-      <code>
-      bkstring str(strSize, 0);<br>
-      FILE * fp = fopen(fileName, "r");<br>
-      fread((char*)str.data(), strSize * 2, 1, fp);<br>
-      fclose(fp);<br>
-      <br>
-      std::vector&lt;bkstring&gt; lines = WCPattern::split(L"[\r\n]+", str, true);<br>
-      <br>
-      </code>
-
-      @param pattern    The regular expression
-      @param replace    The string to split
-      @param keepEmptys Whether or not to keep empty strings
-      @param limit      The maximum number of splits to make
-      @param mode       The special mode requested of the <code>WCPattern</code>
-                        during the split process
-      @return All substrings of <code>str</code> split across <code>pattern</code>.
-     */
-    static std::vector<bkstring>     split         (const bkstring & pattern,
-                                                        const bkstring & str,
-                                                        const bool keepEmptys = 0,
-                                                        const unsigned long limit = 0,
-                                                        const unsigned long mode = 0);
-
-    /**
-      Finds all the instances of the specified pattern within the string. You
-      should be careful to only pass patterns with a minimum length of one. For
-      example, the pattern <code>a*</code> can be matched by an empty string, so
-      instead you should pass <code>a+</code> since at least one character must
-      be matched. A typical invocation of <code>findAll</code> looks like:
-      <p>
-      <code>
-      std::vector&lt;td::string&gt; numbers = WCPattern::findAll(L"\\d+", string);
-      </code>
-      <p>
-
-      @param pattern  The pattern for which to search
-      @param str      The string to search
-      @param mode     The special mode requested of the <code>WCPattern</code>
-                      during the find process
-      @return All instances of <code>pattern</code> in <code>str</code>
-     */
-    static std::vector<bkstring>     findAll       (const bkstring & pattern,
-                                                        const bkstring & str,
-                                                        const unsigned long mode = 0);
-
-    /**
-      Determines if an entire string matches the specified pattern
-
-      @param pattern  The pattern for to match
-      @param str      The string to match
-      @param mode     The special mode requested of the <code>WCPattern</code>
-                      during the replacement process
-      @return True if <code>str</code> is recognized by <code>pattern</code>
-     */
-    static bool                         matches        (const bkstring & pattern,
-                                                        const bkstring & str,
-                                                        const unsigned long mode = 0);
-
-    /**
-      Registers a pattern under a specific name for use in later compilations.
-      A typical invocation and later use looks like:
-      <p>
-      <code>
-      WCPattern::registerWCPattern(L"ip", L"(?:\\d{1,3}\\.){3}\\d{1,3}");<br>
-      WCPattern * p1 = WCPattern::compile(L"{ip}:\\d+");<br>
-      WCPattern * p2 = WCPattern::compile(L"Connection from ({ip}) on port \\d+");<br>
-      </code>
-      <p>
-      Multiple calls to <code>registerWCPattern</code> with the same
-      <code>name</code> will result in the pattern getting overwritten.
-
-      @param name     The name to give to the pattern
-      @param pattern  The pattern to register
-      @param mode     Any special flags to use when compiling pattern
-      @return Success/Failure. Fails only if <code>pattern</code> has invalid
-              syntax
-     */
-    static bool                         registerWCPattern(const bkstring & name,
-                                                        const bkstring & pattern,
-                                                        const unsigned long mode = 0);
-
-    /**
-      Clears the pattern registry
-      */
-    static void                         unregisterWCPatterns();
-    /**
-      Don't use
-     */
-    static void                         clearWCPatternCache();
-
-    /**
-      Searches through a string for the <code>n<sup>th</sup></code> match of the
-      given pattern in the string. Match indeces start at zero, not one.
-      A typical invocation looks like this:
-      <p>
-      <code>
-      std::pair&lt;bkstring, int&gt; match = WCPattern::findNthMatch(L"\\d{1,3}", L"192.168.1.101:22", 1);<br>
-      wprintf(L"%s %i\n", match.first.c_str(), match.second);<br>
-      <br>
-      Output: 168 4<br>
-      <br>
-
-      @param pattern  The pattern for which to search
-      @param str      The string to search
-      @param matchNum Which match to find
-      @param mode     Any special flags to use during the matching process
-      @return A string and an integer. The string is the string matched. The
-              integer is the starting location of the matched string in
-              <code>str</code>. You can check for success/failure by making sure
-              that the integer returned is greater than or equal to zero.
-     */
-    static std::pair<bkstring, int>  findNthMatch   (const bkstring & pattern,
-                                                        const bkstring & str,
-                                                        const int matchNum,
-                                                        const unsigned long mode = 0);
-  public:
-    /**
-      Deletes all NFA nodes allocated during compilation
-     */
-    ~WCPattern();
-
-    bkstring               replace       (const bkstring & str,
-                                              const bkstring & replacementText);
-    std::vector<bkstring>  split         (const bkstring & str, const bool keepEmptys = 0,
-                                              const unsigned long limit = 0);
-    std::vector<bkstring>  findAll       (const bkstring & str);
-    bool                       matches       (const bkstring & str);
-    /**
-      Returns the flags used during compilation of this pattern
-      @return The flags used during compilation of this pattern
-     */
-    unsigned long             getFlags       () const;
-    /**
-      Returns the regular expression this pattern represents
-      @return The regular expression this pattern represents
-     */
-    bkstring               getWCPattern     () const;
-    /**
-      Creates a matcher object using the specified string and this pattern.
-      @param str The string to match against
-      @return A new matcher using object using this pattern and the specified
-              string
-     */
-    WCMatcher                 * createWCMatcher  (const bkstring & str);
+	friend class WCMatcher;
+	friend class NFAUNode;
+	friend class NFAQuantifierUNode;
+private:
+	/**
+	  This constructor should not be called directly. Those wishing to use the
+	  WCPattern class should instead use the {@link compile compile} method.
+
+	  @param rhs The pattern to compile
+	  @memo Creates a new pattern from the regular expression in <code>rhs</code>.
+	  */
+	WCPattern(const CMString & rhs);
+protected:
+	/**
+	  This currently is not used, so don't try to do anything with it.
+	  @memo Holds all the compiled patterns for quick access.
+	  */
+	static std::map<CMString, WCPattern *> compiledWCPatterns;
+	/**
+	  Holds all of the registered patterns as strings. Due to certain problems
+	  with compilation of patterns, especially with capturing groups, this seemed
+	  to be the best way to do it.
+	  */
+	static std::map<CMString, std::pair<CMString, unsigned long> > registeredWCPatterns;
+protected:
+	/**
+	  Holds all the NFA nodes used. This makes deletion of a pattern, as well as
+	  clean-up from an unsuccessful compile much easier and faster.
+	  */
+	std::map<NFAUNode*, bool> nodes;
+	/**
+	  Used when methods like split are called. The matcher class uses a lot of
+	  dynamic memeory, so having an instance increases speedup of certain
+	  operations.
+	  */
+	WCMatcher * matcher;
+	/**
+	  The front node of the NFA.
+	  */
+	NFAUNode * head;
+	/**
+	  The actual regular expression we rerpesent
+	  */
+	CMString pattern;
+	/**
+	  Flag used during compilation. Once the pattern is successfully compiled,
+	  <code>error</code> is no longer used.
+	  */
+	bool error;
+	/**
+	  Used during compilation to keep track of the current index into
+	  <code>{@link pattern pattern}<code>.  Once the pattern is successfully
+	  compiled, <code>error</code> is no longer used.
+	  */
+	int curInd;
+	/**
+	  The number of capture groups this contains.
+	  */
+	int groupCount;
+	/**
+	  The number of non-capture groups this contains.
+	  */
+	int nonCapGroupCount;
+	/**
+	  The flags specified when this was compiled.
+	  */
+	unsigned long flags;
+protected:
+	/**
+	  Raises an error during compilation. Compilation will cease at that point
+	  and compile will return <code>NULL</code>.
+	  */
+	void raiseError();
+	/**
+	  Convenience function for registering a node in <code>nodes</code>.
+	  @param node The node to register
+	  @return The registered node
+	  */
+	NFAUNode * registerNode(NFAUNode * node);
+
+	/**
+	  Calculates the union of two strings. This function will first sort the
+	  strings and then use a simple selection algorithm to find the union.
+	  @param s1 The first "class" to union
+	  @param s2 The second "class" to union
+	  @return A new string containing all unique characters. Each character
+	  must have appeared in one or both of <code>s1</code> and
+	  <code>s2</code>.
+	  */
+	CMString classUnion(CMString s1, CMString s2)  const;
+	/**
+	  Calculates the intersection of two strings. This function will first sort
+	  the strings and then use a simple selection algorithm to find the
+	  intersection.
+	  @param s1 The first "class" to intersect
+	  @param s2 The second "class" to intersect
+	  @return A new string containing all unique characters. Each character
+	  must have appeared both <code>s1</code> and <code>s2</code>.
+	  */
+	CMString classIntersect(CMString s1, CMString s2)  const;
+	/**
+	  Calculates the negation of a string. The negation is the set of all
+	  characters between <code>\x00</code> and <code>\xFF</code> not
+	  contained in <code>s1</code>.
+	  @param s1 The "class" to be negated.
+	  @param s2 The second "class" to intersect
+	  @return A new string containing all unique characters. Each character
+	  must have appeared both <code>s1</code> and <code>s2</code>.
+	  */
+	CMString classNegate(CMString s1)                  const;
+	/**
+	  Creates a new "class" representing the range from <code>low</code> thru
+	  <code>hi</code>. This function will wrap if <code>low</code> &gt;
+	  <code>hi</code>. This is a feature, not a buf. Sometimes it is useful
+	  to be able to say [\x70-\x10] instead of [\x70-\x7F\x00-\x10].
+	  @param low The beginning character
+	  @param hi  The ending character
+	  @return A new string containing all the characters from low thru hi.
+	  */
+	CMString classCreateRange(wchar_t low, wchar_t hi)         const;
+
+	/**
+	  Extracts a decimal number from the substring of member-variable
+	  <code>{@link pattern pattern}<code> starting at <code>start</code> and
+	  ending at <code>end</code>.
+	  @param start The starting index in <code>{@link pattern pattern}<code>
+	  @param end The last index in <code>{@link pattern pattern}<code>
+	  @return The decimal number in <code>{@link pattern pattern}<code>
+	  */
+	int getInt(int start, int end);
+	/**
+	  Parses a <code>{n,m}</code> string out of the member-variable
+	  <code>{@link pattern pattern}<code> stores the result in <code>sNum</code>
+	  and <code>eNum</code>.
+	  @param sNum Output parameter. The minimum number of matches required
+	  by the curly quantifier are stored here.
+	  @param eNum Output parameter. The maximum number of matches allowed
+	  by the curly quantifier are stored here.
+	  @return Success/Failure. Fails when the curly does not have the proper
+	  syntax
+	  */
+	bool quantifyCurly(int & sNum, int & eNum);
+	/**
+	  Tries to quantify the currently parsed group. If the group being parsed
+	  is indeed quantified in the member-variable
+	  <code>{@link pattern pattern}<code>, then the NFA is modified accordingly.
+	  @param start  The starting node of the current group being parsed
+	  @param stop   The ending node of the current group being parsed
+	  @param gn     The group number of the current group being parsed
+	  @return       The node representing the starting node of the group. If the
+	  group becomes quantified, then this node is not necessarily
+	  a GroupHead node.
+	  */
+	NFAUNode * quantifyGroup(NFAUNode * start, NFAUNode * stop, const int gn);
+
+	/**
+	  Tries to quantify the last parsed expression. If the character was indeed
+	  quantified, then the NFA is modified accordingly.
+	  @param newNode The recently created expression node
+	  @return The node representing the last parsed expression. If the
+	  expression was quantified, <code>return value != newNode</code>
+	  */
+	NFAUNode * quantify(NFAUNode * newNode);
+	/**
+	  Parses the current class being examined in
+	  <code>{@link pattern pattern}</code>.
+	  @return A string of unique characters contained in the current class being
+	  parsed
+	  */
+	CMString parseClass();
+	/**
+	  Parses the current POSIX class being examined in
+	  <code>{@link pattern pattern}</code>.
+	  @return A string of unique characters representing the POSIX class being
+	  parsed
+	  */
+	CMString parsePosix();
+	/**
+	  Returns a string containing the octal character being parsed
+	  @return The string contained the octal value being parsed
+	  */
+	CMString parseOctal();
+	/**
+	  Returns a string containing the hex character being parsed
+	  @return The string contained the hex value being parsed
+	  */
+	CMString parseHex();
+	/**
+	  Returns a new node representing the back reference being parsed
+	  @return The new node representing the back reference being parsed
+	  */
+	NFAUNode *   parseBackref();
+	/**
+	  Parses the escape sequence currently being examined. Determines if the
+	  escape sequence is a class, a single character, or the beginning of a
+	  quotation sequence.
+	  @param inv Output parameter. Whether or not to invert the returned class
+	  @param quo Output parameter. Whether or not this sequence starts a
+	  quotation.
+	  @return The characters represented by the class
+	  */
+	CMString parseEscape(bool & inv, bool & quo);
+	/**
+	  Parses a supposed registered pattern currently under compilation. If the
+	  sequence of characters does point to a registered pattern, then the
+	  registered pattern is appended to <code>*end<code>. The registered pattern
+	  is parsed with the current compilation flags.
+	  @param end The ending node of the thus-far compiled pattern
+	  @return The new end node of the current pattern
+	  */
+	NFAUNode * parseRegisteredWCPattern(NFAUNode ** end);
+	/**
+	  Parses a lookbehind expression. Appends the necessary nodes
+	  <code>*end</code>.
+	  @param pos Positive or negative look behind
+	  @param end The ending node of the current pattern
+	  @return The new end node of the current pattern
+	  */
+	NFAUNode * parseBehind(const bool pos, NFAUNode ** end);
+	/**
+	  Parses the current expression and tacks on nodes until a \E is found.
+	  @return The end of the current pattern
+	  */
+	NFAUNode * parseQuote();
+	/**
+	  Parses <code>{@link pattern pattern}</code>. This function is called
+	  recursively when an or (<code>|</code>) or a group is encountered.
+	  @param inParen Are we currently parsing inside a group
+	  @param inOr Are we currently parsing one side of an or (<code>|</code>)
+	  @param end The end of the current expression
+	  @return The starting node of the NFA constructed from this parse
+	  */
+	NFAUNode * parse(const bool inParen = 0, const bool inOr = 0, NFAUNode ** end = NULL);
+public:
+	/// We should match regardless of case
+	const static unsigned long CASE_INSENSITIVE;
+	/// We are implicitly quoted
+	const static unsigned long LITERAL;
+	/// @memo We should treat a <code><b>.</b></code> as [\x00-\x7F]
+	const static unsigned long DOT_MATCHES_ALL;
+	/** <code>^</code> and <code>$</code> should anchor to the beginning and
+		 ending of lines, not all input
+		 */
+	const static unsigned long MULTILINE_MATCHING;
+	/** When enabled, only instances of <code>\n</codes> are recognized as
+		 line terminators
+		 */
+	const static unsigned long UNIX_LINE_MODE;
+	/// The absolute minimum number of matches a quantifier can match (0)
+	const static int MIN_QMATCH;
+	/// The absolute maximum number of matches a quantifier can match (0x7FFFFFFF)
+	const static int MAX_QMATCH;
+public:
+	/**
+	  Call this function to compile a regular expression into a
+	  <code>WCPattern</code> object. Special values can be assigned to
+	  <code>mode</code> when certain non-standard behaviors are expected from
+	  the <code>WCPattern</code> object.
+	  @param pattern The regular expression to compile
+	  @param mode    A bitwise or of flags signalling what special behaviors are
+	  wanted from this <code>WCPattern</code> object
+	  @return If successful, <code>compile</code> returns a <code>WCPattern</code>
+	  pointer. Upon failure, <code>compile</code> returns
+	  <code>NULL</code>
+	  */
+	static WCPattern                    * compile(const CMString & pattern,
+		const unsigned long mode = 0);
+	/**
+	  Dont use this function. This function will compile a pattern, and cache
+	  the result. This will eventually be used as an optimization when people
+	  just want to call static methods using the same pattern over and over
+	  instead of first compiling the pattern and then using the compiled
+	  instance for matching.
+	  @param pattern The regular expression to compile
+	  @param mode    A bitwise or of flags signalling what special behaviors are
+	  wanted from this <code>WCPattern</code> object
+	  @return If successful, <code>compileAndKeep</code> returns a
+	  <code>WCPattern</code> pointer. Upon failure, <code>compile</code>
+	  returns <code>NULL</code>.
+	  */
+	static WCPattern                    * compileAndKeep(const CMString & pattern,
+		const unsigned long mode = 0);
+
+	/**
+	  Searches through <code>replace</code> and replaces all substrings matched
+	  by <code>pattern</code> with <code>str</code>. <code>str</code> may
+	  contain backreferences (e.g. <code>\1</code>) to capture groups. A typical
+	  invocation looks like:
+	  <p>
+	  <code>
+	  WCPattern::replace(L"(a+)b(c+)", L"abcccbbabcbabc", L"\\2b\\1");
+	  </code>
+	  <p>
+	  which would replace <code>abcccbbabcbabc</code> with
+	  <code>cccbabbcbabcba</code>.
+	  @param pattern          The regular expression
+	  @param str              The replacement text
+	  @param replacementText  The string in which to perform replacements
+	  @param mode             The special mode requested of the <code>WCPattern</code>
+	  during the replacement process
+	  @return The text with the replacement string substituted where necessary
+	  */
+	static CMString                  replace(const CMString & pattern,
+		const CMString & str,
+		const CMString & replacementText,
+		const unsigned long mode = 0);
+
+	/**
+	  Splits the specified string over occurrences of the specified pattern.
+	  Empty strings can be optionally ignored. The number of strings returned is
+	  configurable. A typical invocation looks like:
+	  <p>
+	  <code>
+	  CMString str(strSize, 0);<br>
+	  FILE * fp = fopen(fileName, "r");<br>
+	  fread((char*)str.data(), strSize * 2, 1, fp);<br>
+	  fclose(fp);<br>
+	  <br>
+	  std::vector&lt;CMString&gt; lines = WCPattern::split(L"[\r\n]+", str, true);<br>
+	  <br>
+	  </code>
+
+	  @param pattern    The regular expression
+	  @param replace    The string to split
+	  @param keepEmptys Whether or not to keep empty strings
+	  @param limit      The maximum number of splits to make
+	  @param mode       The special mode requested of the <code>WCPattern</code>
+	  during the split process
+	  @return All substrings of <code>str</code> split across <code>pattern</code>.
+	  */
+	static std::vector<CMString>     split(const CMString & pattern,
+		const CMString & str,
+		const bool keepEmptys = 0,
+		const unsigned long limit = 0,
+		const unsigned long mode = 0);
+
+	/**
+	  Finds all the instances of the specified pattern within the string. You
+	  should be careful to only pass patterns with a minimum length of one. For
+	  example, the pattern <code>a*</code> can be matched by an empty string, so
+	  instead you should pass <code>a+</code> since at least one character must
+	  be matched. A typical invocation of <code>findAll</code> looks like:
+	  <p>
+	  <code>
+	  std::vector&lt;td::string&gt; numbers = WCPattern::findAll(L"\\d+", string);
+	  </code>
+	  <p>
+
+	  @param pattern  The pattern for which to search
+	  @param str      The string to search
+	  @param mode     The special mode requested of the <code>WCPattern</code>
+	  during the find process
+	  @return All instances of <code>pattern</code> in <code>str</code>
+	  */
+	static std::vector<CMString>     findAll(const CMString & pattern,
+		const CMString & str,
+		const unsigned long mode = 0);
+
+	/**
+	  Determines if an entire string matches the specified pattern
+
+	  @param pattern  The pattern for to match
+	  @param str      The string to match
+	  @param mode     The special mode requested of the <code>WCPattern</code>
+	  during the replacement process
+	  @return True if <code>str</code> is recognized by <code>pattern</code>
+	  */
+	static bool                         matches(const CMString & pattern,
+		const CMString & str,
+		const unsigned long mode = 0);
+
+	/**
+	  Registers a pattern under a specific name for use in later compilations.
+	  A typical invocation and later use looks like:
+	  <p>
+	  <code>
+	  WCPattern::registerWCPattern(L"ip", L"(?:\\d{1,3}\\.){3}\\d{1,3}");<br>
+	  WCPattern * p1 = WCPattern::compile(L"{ip}:\\d+");<br>
+	  WCPattern * p2 = WCPattern::compile(L"Connection from ({ip}) on port \\d+");<br>
+	  </code>
+	  <p>
+	  Multiple calls to <code>registerWCPattern</code> with the same
+	  <code>name</code> will result in the pattern getting overwritten.
+
+	  @param name     The name to give to the pattern
+	  @param pattern  The pattern to register
+	  @param mode     Any special flags to use when compiling pattern
+	  @return Success/Failure. Fails only if <code>pattern</code> has invalid
+	  syntax
+	  */
+	static bool                         registerWCPattern(const CMString & name,
+		const CMString & pattern,
+		const unsigned long mode = 0);
+
+	/**
+	  Clears the pattern registry
+	  */
+	static void                         unregisterWCPatterns();
+	/**
+	  Don't use
+	  */
+	static void                         clearWCPatternCache();
+
+	/**
+	  Searches through a string for the <code>n<sup>th</sup></code> match of the
+	  given pattern in the string. Match indeces start at zero, not one.
+	  A typical invocation looks like this:
+	  <p>
+	  <code>
+	  std::pair&lt;CMString, int&gt; match = WCPattern::findNthMatch(L"\\d{1,3}", L"192.168.1.101:22", 1);<br>
+	  wprintf(L"%s %i\n", match.first.c_str(), match.second);<br>
+	  <br>
+	  Output: 168 4<br>
+	  <br>
+
+	  @param pattern  The pattern for which to search
+	  @param str      The string to search
+	  @param matchNum Which match to find
+	  @param mode     Any special flags to use during the matching process
+	  @return A string and an integer. The string is the string matched. The
+	  integer is the starting location of the matched string in
+	  <code>str</code>. You can check for success/failure by making sure
+	  that the integer returned is greater than or equal to zero.
+	  */
+	static std::pair<CMString, int>  findNthMatch(const CMString & pattern,
+		const CMString & str,
+		const int matchNum,
+		const unsigned long mode = 0);
+public:
+	/**
+	  Deletes all NFA nodes allocated during compilation
+	  */
+	~WCPattern();
+
+	CMString               replace(const CMString & str,
+		const CMString & replacementText);
+	std::vector<CMString>  split(const CMString & str, const bool keepEmptys = 0,
+		const unsigned long limit = 0);
+	std::vector<CMString>  findAll(const CMString & str);
+	bool                       matches(const CMString & str);
+	/**
+	  Returns the flags used during compilation of this pattern
+	  @return The flags used during compilation of this pattern
+	  */
+	unsigned long             getFlags() const;
+	/**
+	  Returns the regular expression this pattern represents
+	  @return The regular expression this pattern represents
+	  */
+	CMString               getWCPattern() const;
+	/**
+	  Creates a matcher object using the specified string and this pattern.
+	  @param str The string to match against
+	  @return A new matcher using object using this pattern and the specified
+	  string
+	  */
+	WCMatcher                 * createWCMatcher(const CMString & str);
 };
 
 class NFAUNode
 {
-  friend class WCMatcher;
-  public:
-    NFAUNode * next;
-    NFAUNode();
-    virtual ~NFAUNode();
-    virtual void findAllNodes(std::map<NFAUNode*, bool> & soFar);
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const = 0;
-    inline virtual bool isGroupHeadNode()     const { return false; }
-    inline virtual bool isStartOfInputNode()  const { return false; }
+	friend class WCMatcher;
+public:
+	NFAUNode * next;
+	NFAUNode();
+	virtual ~NFAUNode();
+	virtual void findAllNodes(std::map<NFAUNode*, bool> & soFar);
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const = 0;
+	inline virtual bool isGroupHeadNode()     const { return false; }
+	inline virtual bool isStartOfInputNode()  const { return false; }
 };
 class NFACharUNode : public NFAUNode
 {
-  protected:
-    wchar_t ch;
-  public:
-    NFACharUNode(const wchar_t c);
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+protected:
+	wchar_t ch;
+public:
+	NFACharUNode(const wchar_t c);
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 class NFACICharUNode : public NFAUNode
 {
-  protected:
-    wchar_t ch;
-  public:
-    NFACICharUNode(const wchar_t c);
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+protected:
+	wchar_t ch;
+public:
+	NFACICharUNode(const wchar_t c);
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 class NFAStartUNode : public NFAUNode
 {
-  public:
-    NFAStartUNode();
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+public:
+	NFAStartUNode();
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 class NFAEndUNode : public NFAUNode
 {
-  public:
-    NFAEndUNode();
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+public:
+	NFAEndUNode();
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 class NFAQuantifierUNode : public NFAUNode
 {
-  public:
-    int min, max;
-    NFAUNode * inner;
-    virtual void findAllNodes(std::map<NFAUNode*, bool> & soFar);
-    NFAQuantifierUNode(WCPattern * pat, NFAUNode * internal,
-                      const int minMatch = WCPattern::MIN_QMATCH,
-                      const int maxMatch = WCPattern::MAX_QMATCH);
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+public:
+	int min, max;
+	NFAUNode * inner;
+	virtual void findAllNodes(std::map<NFAUNode*, bool> & soFar);
+	NFAQuantifierUNode(WCPattern * pat, NFAUNode * internal,
+		const int minMatch = WCPattern::MIN_QMATCH,
+		const int maxMatch = WCPattern::MAX_QMATCH);
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 class NFAGreedyQuantifierUNode : public NFAQuantifierUNode
 {
-  public:
-    NFAGreedyQuantifierUNode(WCPattern * pat, NFAUNode * internal,
-                            const int minMatch = WCPattern::MIN_QMATCH,
-                            const int maxMatch = WCPattern::MAX_QMATCH);
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
-    virtual int matchInternal(const bkstring & str, WCMatcher * matcher, const int curInd, const int soFar) const;
+public:
+	NFAGreedyQuantifierUNode(WCPattern * pat, NFAUNode * internal,
+		const int minMatch = WCPattern::MIN_QMATCH,
+		const int maxMatch = WCPattern::MAX_QMATCH);
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
+	virtual int matchInternal(const CMString & str, WCMatcher * matcher, const int curInd, const int soFar) const;
 };
 class NFALazyQuantifierUNode : public NFAQuantifierUNode
 {
-  public:
-    NFALazyQuantifierUNode(WCPattern * pat, NFAUNode * internal,
-                          const int minMatch = WCPattern::MIN_QMATCH,
-                          const int maxMatch = WCPattern::MAX_QMATCH);
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+public:
+	NFALazyQuantifierUNode(WCPattern * pat, NFAUNode * internal,
+		const int minMatch = WCPattern::MIN_QMATCH,
+		const int maxMatch = WCPattern::MAX_QMATCH);
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 class NFAPossessiveQuantifierUNode : public NFAQuantifierUNode
 {
-  public:
-    NFAPossessiveQuantifierUNode(WCPattern * pat, NFAUNode * internal,
-                                const int minMatch = WCPattern::MIN_QMATCH,
-                                const int maxMatch = WCPattern::MAX_QMATCH);
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+public:
+	NFAPossessiveQuantifierUNode(WCPattern * pat, NFAUNode * internal,
+		const int minMatch = WCPattern::MIN_QMATCH,
+		const int maxMatch = WCPattern::MAX_QMATCH);
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 class NFAAcceptUNode : public NFAUNode
 {
-  public:
-    NFAAcceptUNode();
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+public:
+	NFAAcceptUNode();
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 class NFAClassUNode : public NFAUNode
 {
-  public:
-    bool inv;
-    std::map<wchar_t, bool> vals;
-    NFAClassUNode(const bool invert = 0);
-    NFAClassUNode(const bkstring & clazz, const bool invert);
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+public:
+	bool inv;
+	std::map<wchar_t, bool> vals;
+	NFAClassUNode(const bool invert = 0);
+	NFAClassUNode(const CMString & clazz, const bool invert);
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 class NFACIClassUNode : public NFAUNode
 {
-  public:
-    bool inv;
-    std::map<wchar_t, bool> vals;
-    NFACIClassUNode(const bool invert = 0);
-    NFACIClassUNode(const bkstring & clazz, const bool invert);
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+public:
+	bool inv;
+	std::map<wchar_t, bool> vals;
+	NFACIClassUNode(const bool invert = 0);
+	NFACIClassUNode(const CMString & clazz, const bool invert);
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 class NFASubStartUNode : public NFAUNode
 {
-  public:
-    NFASubStartUNode();
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+public:
+	NFASubStartUNode();
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 class NFAOrUNode : public NFAUNode
 {
-  public:
-    NFAUNode * one;
-    NFAUNode * two;
-    NFAOrUNode(NFAUNode * first, NFAUNode * second);
-    virtual void findAllNodes(std::map<NFAUNode*, bool> & soFar);
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+public:
+	NFAUNode * one;
+	NFAUNode * two;
+	NFAOrUNode(NFAUNode * first, NFAUNode * second);
+	virtual void findAllNodes(std::map<NFAUNode*, bool> & soFar);
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 class NFAQuoteUNode : public NFAUNode
 {
-  public:
-    bkstring qStr;
-    NFAQuoteUNode(const bkstring & quoted);
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+public:
+	CMString qStr;
+	NFAQuoteUNode(const CMString & quoted);
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 class NFACIQuoteUNode : public NFAUNode
 {
-  public:
-    bkstring qStr;
-    NFACIQuoteUNode(const bkstring & quoted);
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+public:
+	CMString qStr;
+	NFACIQuoteUNode(const CMString & quoted);
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 class NFALookAheadUNode : public NFAUNode
 {
-  public:
-    bool pos;
-    NFAUNode * inner;
-    NFALookAheadUNode(NFAUNode * internal, const bool positive);
-    virtual void findAllNodes(std::map<NFAUNode*, bool> & soFar);
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+public:
+	bool pos;
+	NFAUNode * inner;
+	NFALookAheadUNode(NFAUNode * internal, const bool positive);
+	virtual void findAllNodes(std::map<NFAUNode*, bool> & soFar);
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 class NFALookBehindUNode : public NFAUNode
 {
-  public:
-    bool pos;
-    bkstring mStr;
-    NFALookBehindUNode(const bkstring & str, const bool positive);
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+public:
+	bool pos;
+	CMString mStr;
+	NFALookBehindUNode(const CMString & str, const bool positive);
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 class NFAStartOfLineUNode : public NFAUNode
 {
-  public:
-    NFAStartOfLineUNode();
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+public:
+	NFAStartOfLineUNode();
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 class NFAEndOfLineUNode : public NFAUNode
 {
-  public:
-    NFAEndOfLineUNode();
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+public:
+	NFAEndOfLineUNode();
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 class NFAReferenceUNode : public NFAUNode
 {
-  public:
-    int gi;
-    NFAReferenceUNode(const int groupIndex);
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+public:
+	int gi;
+	NFAReferenceUNode(const int groupIndex);
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 class NFAStartOfInputUNode : public NFAUNode
 {
-  public:
-    NFAStartOfInputUNode();
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
-    inline virtual bool isStartOfInputNode()  const { return false; }
+public:
+	NFAStartOfInputUNode();
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
+	inline virtual bool isStartOfInputNode()  const { return false; }
 };
 class NFAEndOfInputUNode : public NFAUNode
 {
-  public:
-    bool term;
-    NFAEndOfInputUNode(const bool lookForTerm);
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+public:
+	bool term;
+	NFAEndOfInputUNode(const bool lookForTerm);
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 class NFAWordBoundaryUNode : public NFAUNode
 {
-  public:
-    bool pos;
-    NFAWordBoundaryUNode(const bool positive);
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+public:
+	bool pos;
+	NFAWordBoundaryUNode(const bool positive);
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 class NFAEndOfMatchUNode : public NFAUNode
 {
-  public:
-    NFAEndOfMatchUNode();
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+public:
+	NFAEndOfMatchUNode();
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 class NFAGroupHeadUNode : public NFAUNode
 {
-  public:
-    int gi;
-    NFAGroupHeadUNode(const int groupIndex);
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
-    inline virtual bool isGroupHeadNode()     const { return false; }
+public:
+	int gi;
+	NFAGroupHeadUNode(const int groupIndex);
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
+	inline virtual bool isGroupHeadNode()     const { return false; }
 };
 class NFAGroupTailUNode : public NFAUNode
 {
-  public:
-    int gi;
-    NFAGroupTailUNode(const int groupIndex);
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+public:
+	int gi;
+	NFAGroupTailUNode(const int groupIndex);
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 class NFAGroupLoopPrologueUNode : public NFAUNode
 {
-  public:
-    int gi;
-    NFAGroupLoopPrologueUNode(const int groupIndex);
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+public:
+	int gi;
+	NFAGroupLoopPrologueUNode(const int groupIndex);
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 class NFAGroupLoopUNode : public NFAUNode
 {
-  public:
-    int gi, min, max, type;
-    NFAUNode * inner;
-    NFAGroupLoopUNode(NFAUNode * internal, const int minMatch,
-                     const int maxMatch, const int groupIndex, const int matchType);
-    virtual void findAllNodes(std::map<NFAUNode*, bool> & soFar);
-    virtual int match(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
-    int matchGreedy(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
-    int matchLazy(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
-    int matchPossessive(const bkstring & str, WCMatcher * matcher, const int curInd = 0) const;
+public:
+	int gi, min, max, type;
+	NFAUNode * inner;
+	NFAGroupLoopUNode(NFAUNode * internal, const int minMatch,
+		const int maxMatch, const int groupIndex, const int matchType);
+	virtual void findAllNodes(std::map<NFAUNode*, bool> & soFar);
+	virtual int match(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
+	int matchGreedy(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
+	int matchLazy(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
+	int matchPossessive(const CMString & str, WCMatcher * matcher, const int curInd = 0) const;
 };
 
 #endif
diff --git a/plugins/SmileyAdd/src/services.cpp b/plugins/SmileyAdd/src/services.cpp
index 30717b81c1..f42e23978b 100644
--- a/plugins/SmileyAdd/src/services.cpp
+++ b/plugins/SmileyAdd/src/services.cpp
@@ -25,52 +25,41 @@ LIST<void> menuHandleArray(5);
 
 SmileyPackType* GetSmileyPack(const char* proto, HANDLE hContact, SmileyPackCType** smlc)
 {
-	bkstring categoryName;
-
 	hContact = DecodeMetaContact(hContact);
-	if (smlc) *smlc = opt.DisableCustom ? NULL : g_SmileyPackCStore.GetSmileyPack(hContact);
+	if (smlc)
+		*smlc = opt.DisableCustom ? NULL : g_SmileyPackCStore.GetSmileyPack(hContact);
 
-	if (proto != NULL && IsBadStringPtrA(proto, 10)) return NULL;
+	if (proto != NULL && IsBadStringPtrA(proto, 10))
+		return NULL;
 
-	if (hContact != NULL)
-	{
+	CMString categoryName;
+	if (hContact != NULL) {
 		opt.ReadContactCategory(hContact, categoryName);
 		if (categoryName == _T("<None>")) return NULL;
-		if (!categoryName.empty() && 
-			g_SmileyCategories.GetSmileyCategory(categoryName) == NULL)
-		{
-			categoryName.clear();
+		if (!categoryName.IsEmpty() && g_SmileyCategories.GetSmileyCategory(categoryName) == NULL) {
+			categoryName.Empty();
 			opt.WriteContactCategory(hContact, categoryName);
 		}
 
-		if (categoryName.empty() && !opt.UseOneForAll)
-		{
+		if (categoryName.IsEmpty() && !opt.UseOneForAll) {
 			char *protonam = GetContactProto(hContact);
-			if (protonam != NULL)
-			{
+			if (protonam != NULL) {
 				DBVARIANT dbv;
-				if (db_get_ts(hContact, protonam, "Transport", &dbv) == 0)
-				{
+				if (db_get_ts(hContact, protonam, "Transport", &dbv) == 0) {
 					categoryName = dbv.ptszVal;
 					db_free(&dbv);
 				}
-				else
-					categoryName = A2T_SM(protonam);
+				else categoryName = A2T_SM(protonam);
 			}
 		}
 	}
 
-	if (categoryName.empty())
-	{
+	if (categoryName.IsEmpty()) {
 		if (proto == NULL || proto[0] == 0)
-		{
 			categoryName = _T("Standard");
-		}
-		else 
-		{
+		else {
 			categoryName = A2T_SM(proto);
-			if (opt.UseOneForAll) 
-			{
+			if (opt.UseOneForAll) {
 				SmileyCategoryType *smc = g_SmileyCategories.GetSmileyCategory(categoryName);
 				if (smc == NULL || smc->IsProto()) categoryName = _T("Standard");
 			}
@@ -84,7 +73,8 @@ SmileyPackType* GetSmileyPack(const char* proto, HANDLE hContact, SmileyPackCTyp
 INT_PTR ReplaceSmileysCommand(WPARAM, LPARAM lParam)
 {
 	SMADD_RICHEDIT3* smre = (SMADD_RICHEDIT3*) lParam;
-	if (smre == NULL || smre->cbSize < SMADD_RICHEDIT_SIZE_V1) return FALSE;
+	if (smre == NULL || smre->cbSize < SMADD_RICHEDIT_SIZE_V1)
+		return FALSE;
 
 	SMADD_RICHEDIT3 smrec = {0};
 	memcpy(&smrec, smre, min(smre->cbSize, sizeof(smrec)));
@@ -137,8 +127,7 @@ INT_PTR GetSmileyIconCommand(WPARAM, LPARAM lParam)
 
 	SmileyPackType* SmileyPack = GetSmileyPack(smre->Protocolname);
 
-	if (SmileyPack == NULL || IsBadStringPtrA(smre->SmileySequence, MAX_SMILEY_LENGTH))
-	{
+	if (SmileyPack == NULL || IsBadStringPtrA(smre->SmileySequence, MAX_SMILEY_LENGTH)) {
 		smre->SmileyIcon = NULL;
 		smre->Smileylength = 0;
 		return FALSE;
@@ -356,10 +345,10 @@ INT_PTR RegisterPack(WPARAM, LPARAM lParam)
 
 
 
-	bkstring nmd(A2W_SM(smre->dispname, lpcp));
+	CMString nmd(A2W_SM(smre->dispname, lpcp));
 
 
-	bkstring nm(A2T_SM(smre->name));
+	CMString nm(A2T_SM(smre->name));
 	g_SmileyCategories.AddAndLoad(nm, nmd);
 
 	return TRUE;
@@ -375,7 +364,7 @@ INT_PTR CustomCatMenu(WPARAM wParam, LPARAM lParam)
 			opt.WriteContactCategory(hContact, smct->GetName());
 		else
 		{
-			bkstring empty;
+			CMString empty;
 			if (lParam == 1) empty = _T("<None>");
 			opt.WriteContactCategory(hContact, empty);
 		}
@@ -410,7 +399,7 @@ int RebuildContactMenu(WPARAM wParam, LPARAM)
 	menuHandleArray.destroy();
 
 	if (haveMenu) {
-		bkstring cat;
+		CMString cat;
 		opt.ReadContactCategory((HANDLE)wParam, cat);
 
 		CLISTMENUITEM mi = { sizeof(mi) };
@@ -468,7 +457,7 @@ INT_PTR ReloadPack(WPARAM, LPARAM lParam)
 {
 	if (lParam)
 	{
-		bkstring categoryName = A2T_SM((char*)lParam);
+		CMString categoryName = A2T_SM((char*)lParam);
 		SmileyCategoryType *smc = g_SmileyCategories.GetSmileyCategory(categoryName);
 		if (smc != NULL) smc->Load();
 	}
@@ -509,8 +498,8 @@ int AccountListChanged(WPARAM wParam, LPARAM lParam)
 	case PRAC_ADDED:
 		if (acc != NULL)
 		{
-			bkstring catname(_T("Standard"));
-			const bkstring& defaultFile = g_SmileyCategories.GetSmileyCategory(catname)->GetFilename();
+			CMString catname(_T("Standard"));
+			const CMString& defaultFile = g_SmileyCategories.GetSmileyCategory(catname)->GetFilename();
 			g_SmileyCategories.AddAccountAsCategory(acc, defaultFile);
 		}
 		break;
@@ -518,7 +507,7 @@ int AccountListChanged(WPARAM wParam, LPARAM lParam)
 	case PRAC_CHANGED:
 		if (acc != NULL && acc->szModuleName != NULL)
 		{
-			bkstring name(A2T_SM(acc->szModuleName));
+			CMString name(A2T_SM(acc->szModuleName));
 			SmileyCategoryType* smc = g_SmileyCategories.GetSmileyCategory(name);
 			if (smc != NULL)
 			{
@@ -537,8 +526,8 @@ int AccountListChanged(WPARAM wParam, LPARAM lParam)
 		{
 			if (acc->bIsEnabled)
 			{
-				bkstring catname(_T("Standard"));
-				const bkstring& defaultFile = g_SmileyCategories.GetSmileyCategory(catname)->GetFilename();
+				CMString catname(_T("Standard"));
+				const CMString& defaultFile = g_SmileyCategories.GetSmileyCategory(catname)->GetFilename();
 				g_SmileyCategories.AddAccountAsCategory(acc, defaultFile);
 			}
 			else
@@ -561,7 +550,7 @@ int DbSettingChanged(WPARAM wParam, LPARAM lParam)
 
 	if (strcmp(cws->szSetting, "Transport") == 0) 
 	{
-		bkstring catname(_T("Standard"));
+		CMString catname(_T("Standard"));
 		SmileyCategoryType *smc = g_SmileyCategories.GetSmileyCategory(catname);
 		if (smc != NULL)
 			g_SmileyCategories.AddContactTransportAsCategory(hContact, smc->GetFilename());
diff --git a/plugins/SmileyAdd/src/smileyroutines.cpp b/plugins/SmileyAdd/src/smileyroutines.cpp
index 67c011d1ea..cdabaa712a 100644
--- a/plugins/SmileyAdd/src/smileyroutines.cpp
+++ b/plugins/SmileyAdd/src/smileyroutines.cpp
@@ -48,18 +48,18 @@ void LookupAllSmileys(SmileyPackType* smileyPack, SmileyPackCType* smileyCPack,
 	SmileyLookup::SmileyLocVecType* smileys = new SmileyLookup::SmileyLocVecType [smlsz];
 
 	// Find all possible smileys
-	bkstring tmpstr(lpstrText);
+	CMString tmpstr(lpstrText);
 	int i = 0;
 
 	if (sml)
 		for (int j=0; j < sml->getCount(); j++) {
-			(*sml)[j].find(tmpstr, smileys[i], false);
+			(*sml)[j].Find(tmpstr, smileys[i], false);
 			i++;
 		}
 
 	if (smlc)
 		for (int j=0; j < smlc->getCount(); j++) {
-			(*smlc)[j].find(tmpstr, smileys[i], false);
+			(*smlc)[j].Find(tmpstr, smileys[i], false);
 			i++;
 		}
 
@@ -67,7 +67,7 @@ void LookupAllSmileys(SmileyPackType* smileyPack, SmileyPackCType* smileyCPack,
 	memset(csmlit, 0, smlsz * sizeof(int));
 
 	long numCharsSoFar = 0;
-	bkstring::size_type smloff = 0;
+	int smloff = 0;
 
 	while (true) {
 		int firstSml = -1;
@@ -137,7 +137,7 @@ void LookupAllSmileys(SmileyPackType* smileyPack, SmileyPackCType* smileyCPack,
 		else delete dat;
 
 		// Advance string pointer to search for the next smiley
-		smloff = (*smlf)[firstSmlRef].pos + (*smlf)[firstSmlRef].len;
+		smloff = int((*smlf)[firstSmlRef].pos + (*smlf)[firstSmlRef].len);
 		csmlit[firstSml]++;
 	}
 	delete[] smileys;
diff --git a/plugins/SmileyAdd/src/smileys.cpp b/plugins/SmileyAdd/src/smileys.cpp
index e81bc18c28..94da1c34bd 100644
--- a/plugins/SmileyAdd/src/smileys.cpp
+++ b/plugins/SmileyAdd/src/smileys.cpp
@@ -75,14 +75,14 @@ bool SmileyType::LoadFromImage(IStream* pStream)
 {
 	if (m_xepimg) m_xepimg->Release();
 
-	bkstring name;
+	CMString name;
 	m_xepimg = new ImageType(0, name, pStream);
 
 	return true;
 }
 
 
-bool SmileyType::LoadFromResource(const bkstring& file, const int index)
+bool SmileyType::LoadFromResource(const CMString& file, const int index)
 {
 	m_index = index;
 	m_filepath = file;
@@ -174,9 +174,9 @@ void SmileyType::CallSmileyService(HANDLE hContact)
 	_TMatcher * m0 = srvsplit->createTMatcher(GetTriggerText());
 	m0->findFirstMatch();
 
-	bkstring name = m0->getGroup(1);
-	bkstring par1 = m0->getGroup(2);
-	bkstring par2 = m0->getGroup(3);
+	CMString name = m0->getGroup(1);
+	CMString par1 = m0->getGroup(2);
+	CMString par2 = m0->getGroup(3);
 
 	delete m0;
 	delete srvsplit;
@@ -211,7 +211,7 @@ void SmileyPackType::AddTriggersToSmileyLookup(void)
 {
 	_TPattern * p = _TPattern::compile(_T("\\s+"));
 	{
-		bkstring emptystr;
+		CMString emptystr;
 		m_SmileyLookup.insert(new SmileyLookup(urlRegEx, true, -1, emptystr));
 		m_SmileyLookup.insert(new SmileyLookup(pathRegEx, true, -1, emptystr));
 		m_SmileyLookup.insert(new SmileyLookup(timeRegEx, true, -1, emptystr));
@@ -224,7 +224,8 @@ void SmileyPackType::AddTriggersToSmileyLookup(void)
 				m_SmileyLookup.insert(dats);
 			else 
 				errorFound = true;
-			if (m_SmileyList[dist].m_InsertText.empty()) m_SmileyList[dist].m_InsertText = m_SmileyList[dist].m_ToolText;
+			if (m_SmileyList[dist].m_InsertText.IsEmpty())
+				m_SmileyList[dist].m_InsertText = m_SmileyList[dist].m_ToolText;
 		}
 		else if (!m_SmileyList[dist].IsService()) {
 			bool first = true;
@@ -234,8 +235,8 @@ void SmileyPackType::AddTriggersToSmileyLookup(void)
 			{	
 				int stind = m0->getStartingIndex();
 				if (li != stind) {
-					bkstring out;
-					ReplaceAllSpecials(m0->getString().substr(li, stind - li), out);
+					CMString out;
+					ReplaceAllSpecials(m0->getString().Mid(li, stind - li), out);
 					SmileyLookup *dats = new SmileyLookup(out, false, dist, GetFilename()); 
 					if (dats->IsValid()) {
 						m_SmileyLookup.insert(dats);
@@ -248,10 +249,10 @@ void SmileyPackType::AddTriggersToSmileyLookup(void)
 				li = m0->getEndingIndex();
 			}
 
-			int stind = (int)m0->getString().size();
+			int stind = (int)m0->getString().GetLength();
 			if (li < stind) {
-				bkstring out;
-				ReplaceAllSpecials(m0->getString().substr(li, stind - li), out);
+				CMString out;
+				ReplaceAllSpecials(m0->getString().Mid(li, stind - li), out);
 				SmileyLookup *dats = new SmileyLookup(out, false, dist, GetFilename()); 
 				if (dats->IsValid()) {
 					m_SmileyLookup.insert(dats);
@@ -267,7 +268,7 @@ void SmileyPackType::AddTriggersToSmileyLookup(void)
 	delete p;
 }
 
-void SmileyPackType::ReplaceAllSpecials(const bkstring& Input, bkstring& Output)
+void SmileyPackType::ReplaceAllSpecials(const CMString& Input, CMString& Output)
 {
 	Output = _TPattern::replace(_T("%%_{1,2}%%"), Input, _T(" "));
 	Output = _TPattern::replace(_T("%%''%%"), Output, _T("\""));
@@ -278,26 +279,26 @@ void SmileyPackType::Clear(void)
 	m_SmileyList.destroy();
 	m_SmileyLookup.destroy();
 	if (m_hSmList != NULL) { ImageList_Destroy(m_hSmList); m_hSmList = NULL; }
-	m_Filename.clear();
-	m_Name.clear();
-	m_Date.clear();
-	m_Version.clear();
-	m_Author.clear();
+	m_Filename.Empty();
+	m_Name.Empty();
+	m_Date.Empty();
+	m_Version.Empty();
+	m_Author.Empty();
 	m_VisibleCount = 0;
-	m_ButtonSmiley.clear();
+	m_ButtonSmiley.Empty();
 	errorFound = false;
 }
 
-bool SmileyPackType::LoadSmileyFile(const bkstring& filename, bool onlyInfo, bool noerr)
+bool SmileyPackType::LoadSmileyFile(const CMString& filename, bool onlyInfo, bool noerr)
 {
 	Clear();
 
-	if (filename.empty()) {
+	if (filename.IsEmpty()) {
 		m_Name = _T("Nothing loaded");
 		return false;
 	}
 
-	bkstring modpath;
+	CMString modpath;
 	pathToAbsolute(filename, modpath);
 
 	// Load xep file
@@ -329,7 +330,7 @@ bool SmileyPackType::LoadSmileyFile(const bkstring& filename, bool onlyInfo, boo
 	// Close file
 	_close(fh);
 
-	bkstring tbuf;
+	CMString tbuf;
 
 	if (len>2 && *(wchar_t*)buf == 0xfeff)
 		tbuf = W2T_SM((wchar_t*)buf+1);
@@ -341,7 +342,7 @@ bool SmileyPackType::LoadSmileyFile(const bkstring& filename, bool onlyInfo, boo
 	delete[] buf;
 
 	bool res;
-	if (filename.find(_T(".xep")) == filename.npos) 
+	if (filename.Find(_T(".xep")) == -1) 
 		res = LoadSmileyFileMSL(tbuf, onlyInfo, modpath);
 	else
 		res = LoadSmileyFileXEP(tbuf, onlyInfo, modpath);
@@ -352,14 +353,14 @@ bool SmileyPackType::LoadSmileyFile(const bkstring& filename, bool onlyInfo, boo
 	return res;
 }
 
-bool SmileyPackType::LoadSmileyFileMSL(bkstring& tbuf, bool onlyInfo, bkstring& modpath) 
+bool SmileyPackType::LoadSmileyFileMSL(CMString& tbuf, bool onlyInfo, CMString& modpath) 
 {
 	_TPattern * pathsplit = _TPattern::compile(_T("(.*\\\\)(.*)\\.|$"));
 	_TMatcher * m0 = pathsplit->createTMatcher(modpath);
 
 	m0->findFirstMatch();
-	const bkstring pathstr = m0->getGroup(1);
-	const bkstring packstr = m0->getGroup(2);
+	const CMString pathstr = m0->getGroup(1);
+	const CMString packstr = m0->getGroup(2);
 
 	delete m0;
 	delete pathsplit;
@@ -421,31 +422,26 @@ bool SmileyPackType::LoadSmileyFileMSL(bkstring& tbuf, bool onlyInfo, bkstring&
 		SmileyVectorType hiddenSmileys;
 
 		unsigned smnum = 0;
-		while (m0->findNextMatch())
-		{
-			bkstring resname = m0->getGroup(2);
-			if (resname.find(_T("http://")) != resname.npos)
-			{
-				if (GetSmileyFile(resname, packstr)) continue;
-			}
-			else
-			{
-				if (!resname.empty()) resname.insert(0, pathstr);
+		while (m0->findNextMatch()) {
+			CMString resname = m0->getGroup(2);
+			if (resname.Find(_T("http://")) != -1) {
+				if (GetSmileyFile(resname, packstr))
+					continue;
 			}
+			else if (!resname.IsEmpty())
+				resname.Insert(0, pathstr);
 
 			SmileyType *dat = new SmileyType;
 
 			const int iconIndex = _ttol(m0->getGroup(3).c_str());
 
 			dat->SetHidden(m0->getStartingIndex(1) >= 0);
-			if (m0->getStartingIndex(4) >= 0)
-			{
+			if (m0->getStartingIndex(4) >= 0) {
 				dat->SetRegEx(m0->getGroup(4) == _T("R"));
 				dat->SetService(m0->getGroup(4) == _T("S"));
 			}
 			dat->m_TriggerText = m0->getGroup(5);
-			if (dat->IsRegEx())
-			{
+			if (dat->IsRegEx()) {
 				if (m0->getStartingIndex(6) >= 0)
 					ReplaceAllSpecials(m0->getGroup(6), dat->m_InsertText);
 
@@ -454,8 +450,7 @@ bool SmileyPackType::LoadSmileyFileMSL(bkstring& tbuf, bool onlyInfo, bkstring&
 				else
 					dat->m_ToolText = dat->m_InsertText;
 			}
-			else
-			{
+			else {
 				if (m0->getStartingIndex(6) >= 0)
 					ReplaceAllSpecials(m0->getGroup(6), dat->m_ToolText);
 				else
@@ -463,8 +458,7 @@ bool SmileyPackType::LoadSmileyFileMSL(bkstring& tbuf, bool onlyInfo, bkstring&
 			}
 
 			bool noerr;
-			if (resname.empty())
-			{
+			if (resname.IsEmpty()) {
 				dat->SetHidden(true);
 				dat->SetText(true);
 				noerr = true;
@@ -477,8 +471,7 @@ bool SmileyPackType::LoadSmileyFileMSL(bkstring& tbuf, bool onlyInfo, bkstring&
 			else
 				m_SmileyList.insert(dat);
 
-			if (!noerr)
-			{
+			if (!noerr) {
 				static const TCHAR errmsg[] = LPGENT("Smiley #%u in file %s for Smiley Pack %s not found."); 
 				TCHAR msgtxt[1024];
 				mir_sntprintf(msgtxt, SIZEOF(msgtxt), TranslateTS(errmsg), smnum, resname.c_str(), modpath.c_str());
@@ -501,12 +494,11 @@ bool SmileyPackType::LoadSmileyFileMSL(bkstring& tbuf, bool onlyInfo, bkstring&
 }
 
 
-static void DecodeHTML(bkstring& str)
+static void DecodeHTML(CMString& str)
 {
-	if (str.find('&') != str.npos)
-	{
-		str = _TPattern::replace(bkstring(_T("&lt;")), str, bkstring(_T("<")));
-		str = _TPattern::replace(bkstring(_T("&gt;")), str, bkstring(_T(">")));
+	if (str.Find('&') != -1) {
+		str = _TPattern::replace(CMString(_T("&lt;")), str, CMString(_T("<")));
+		str = _TPattern::replace(CMString(_T("&gt;")), str, CMString(_T(">")));
 	}
 }
 
@@ -533,7 +525,7 @@ static IStream* DecodeBase64Data(const char* pData)
 }
 
 
-bool SmileyPackType::LoadSmileyFileXEP(bkstring& tbuf, bool onlyInfo, bkstring& )
+bool SmileyPackType::LoadSmileyFileXEP(CMString& tbuf, bool onlyInfo, CMString& )
 {
 	_TMatcher *m0, *m1, *m2;
 
@@ -547,7 +539,7 @@ bool SmileyPackType::LoadSmileyFileXEP(bkstring& tbuf, bool onlyInfo, bkstring&
 	m0 = settings_re->createTMatcher(tbuf);
 	if (m0->findFirstMatch())
 	{
-		bkstring settings = m0->getGroup(1);
+		CMString settings = m0->getGroup(1);
 
 		m1 = author_re->createTMatcher(settings);
 		if (m1->findFirstMatch())
@@ -589,7 +581,7 @@ bool SmileyPackType::LoadSmileyFileXEP(bkstring& tbuf, bool onlyInfo, bkstring&
 		m0 = images_re->createTMatcher(tbuf);
 		if (m0->findFirstMatch())
 		{
-			bkstring images = m0->getGroup(1);
+			CMString images = m0->getGroup(1);
 
 			m1 = imagedt_re->createTMatcher(images);
 			if (m1->findFirstMatch())
@@ -616,7 +608,7 @@ bool SmileyPackType::LoadSmileyFileXEP(bkstring& tbuf, bool onlyInfo, bkstring&
 			dat->m_ToolText = m0->getGroup(2);
 			DecodeHTML(dat->m_ToolText);
 
-			bkstring rec = m0->getGroup(3);
+			CMString rec = m0->getGroup(3);
 
 			m1 = expression_re->createTMatcher(rec);
 			if (m1->findFirstMatch())
@@ -633,12 +625,12 @@ bool SmileyPackType::LoadSmileyFileXEP(bkstring& tbuf, bool onlyInfo, bkstring&
 				DecodeHTML(dat->m_InsertText);
 			}
 			delete m1;
-			dat->SetHidden(dat->m_InsertText.empty());
+			dat->SetHidden(dat->m_InsertText.IsEmpty());
 
 			m1 = image_re->createTMatcher(rec);
 			if (m1->findFirstMatch())
 			{
-				bkstring images = m1->getGroup(1);
+				CMString images = m1->getGroup(1);
 
 				m2 = imagedt_re->createTMatcher(images);
 				if (m2->findFirstMatch())
@@ -684,7 +676,7 @@ bool SmileyPackType::LoadSmileyFileXEP(bkstring& tbuf, bool onlyInfo, bkstring&
 //
 
 
-bool SmileyPackListType::AddSmileyPack(bkstring& filename)
+bool SmileyPackListType::AddSmileyPack(CMString& filename)
 {
 	bool res = true;
 	if (GetSmileyPack(filename) == NULL)
@@ -701,13 +693,13 @@ bool SmileyPackListType::AddSmileyPack(bkstring& filename)
 }
 
 
-SmileyPackType* SmileyPackListType::GetSmileyPack(bkstring& filename)
+SmileyPackType* SmileyPackListType::GetSmileyPack(CMString& filename)
 {
-	bkstring modpath;
+	CMString modpath;
 	pathToAbsolute(filename, modpath);
 
 	for (int i=0; i < m_SmileyPacks.getCount(); i++) {
-		bkstring modpath1;
+		CMString modpath1;
 		pathToAbsolute(m_SmileyPacks[i].GetFilename(), modpath1);
 		if (lstrcmpi(modpath.c_str(), modpath1.c_str()) == 0) return &m_SmileyPacks[i];
 	}
@@ -725,9 +717,9 @@ void SmileyPackListType::ClearAndFreeAll()
 //
 
 
-SmileyCategoryType::SmileyCategoryType(SmileyPackListType* pSPS, const bkstring& name, 
-	const bkstring& displayName, 
-	const bkstring& defaultFilename, SmcType typ)
+SmileyCategoryType::SmileyCategoryType(SmileyPackListType* pSPS, const CMString& name, 
+	const CMString& displayName, 
+	const CMString& defaultFilename, SmcType typ)
 { 
 	m_pSmileyPackStore = pSPS; 
 	type = typ; 
@@ -769,10 +761,10 @@ void SmileyCategoryListType::ClearAndLoadAll(void)
 }
 
 
-SmileyCategoryType* SmileyCategoryListType::GetSmileyCategory(const bkstring& name)
+SmileyCategoryType* SmileyCategoryListType::GetSmileyCategory(const CMString& name)
 {
 	for (int i=0; i < m_SmileyCategories.getCount(); i++)
-		if (name.comparei(m_SmileyCategories[i].GetName()) == 0)
+		if (name.CompareNoCase(m_SmileyCategories[i].GetName()) == 0)
 			return &m_SmileyCategories[i];
 
 	return NULL;
@@ -785,7 +777,7 @@ SmileyCategoryType* SmileyCategoryListType::GetSmileyCategory(unsigned index)
 }
 
 
-SmileyPackType* SmileyCategoryListType::GetSmileyPack(bkstring& categoryname) 
+SmileyPackType* SmileyCategoryListType::GetSmileyPack(CMString& categoryname) 
 {
 	SmileyCategoryType* smc = GetSmileyCategory(categoryname);
 	return smc != NULL ? smc->GetSmileyPack() : NULL; 
@@ -794,11 +786,11 @@ SmileyPackType* SmileyCategoryListType::GetSmileyPack(bkstring& categoryname)
 
 void SmileyCategoryListType::SaveSettings(void)
 {
-	bkstring catstr;
+	CMString catstr;
 	for (int i=0; i < m_SmileyCategories.getCount(); i++) {
 		m_SmileyCategories[i].SaveSettings();
 		if (m_SmileyCategories[i].IsCustom()) {
-			if (!catstr.empty()) catstr += '#';
+			if (!catstr.IsEmpty()) catstr += '#';
 			catstr += m_SmileyCategories[i].GetName();
 		}
 	}
@@ -806,7 +798,7 @@ void SmileyCategoryListType::SaveSettings(void)
 }
 
 
-void SmileyCategoryListType::AddAndLoad(const bkstring& name, const bkstring& displayName)
+void SmileyCategoryListType::AddAndLoad(const CMString& name, const CMString& displayName)
 {
 	if (GetSmileyCategory(name) != NULL)
 		return;
@@ -818,8 +810,8 @@ void SmileyCategoryListType::AddAndLoad(const bkstring& name, const bkstring& di
 }
 
 
-void SmileyCategoryListType::AddCategory(const bkstring& name, const bkstring& displayName, 
-	SmcType typ, const bkstring& defaultFilename)
+void SmileyCategoryListType::AddCategory(const CMString& name, const CMString& displayName, 
+	SmcType typ, const CMString& defaultFilename)
 {
 	if (GetSmileyCategory(name) == NULL)
 		m_SmileyCategories.insert(new SmileyCategoryType(m_pSmileyPackStore, name, 
@@ -838,11 +830,11 @@ bool SmileyCategoryListType::DeleteCustomCategory(int index)
 	return false;
 }
 
-void SmileyCategoryListType::AddAccountAsCategory(PROTOACCOUNT *acc, const bkstring& defaultFile)
+void SmileyCategoryListType::AddAccountAsCategory(PROTOACCOUNT *acc, const CMString& defaultFile)
 {
 	if (IsAccountEnabled(acc) && acc->szProtoName && IsSmileyProto(acc->szModuleName))
 	{
-		bkstring displayName(acc->tszAccountName ? acc->tszAccountName : A2T_SM(acc->szModuleName));
+		CMString displayName(acc->tszAccountName ? acc->tszAccountName : A2T_SM(acc->szModuleName));
 
 		const char* packnam = acc->szProtoName;
 		if (strcmp(packnam, "JABBER") == 0)
@@ -853,20 +845,20 @@ void SmileyCategoryListType::AddAccountAsCategory(PROTOACCOUNT *acc, const bkstr
 		char path[MAX_PATH];
 		mir_snprintf(path, sizeof(path), "Smileys\\nova\\%s.msl", packnam);
 
-		bkstring paths = A2T_SM(path), patha; 
+		CMString paths = A2T_SM(path), patha; 
 		pathToAbsolute(paths, patha);
 
 		if (_taccess(patha.c_str(), 0) != 0) 
 			paths = defaultFile;
 
-		bkstring tname(A2T_SM(acc->szModuleName));
+		CMString tname(A2T_SM(acc->szModuleName));
 		AddCategory(tname, displayName, smcProto, paths); 
 	}
 }
 
 void SmileyCategoryListType::DeleteAccountAsCategory(PROTOACCOUNT *acc)
 {
-	bkstring tname(A2T_SM(acc->szModuleName));
+	CMString tname(A2T_SM(acc->szModuleName));
 
 	for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
 		char* proto = GetContactProto(hContact);
@@ -875,7 +867,7 @@ void SmileyCategoryListType::DeleteAccountAsCategory(PROTOACCOUNT *acc)
 
 		DBVARIANT dbv;
 		if (!db_get_ts(hContact, proto, "Transport", &dbv)) {
-			bool found = (tname.comparei(dbv.ptszVal) == 0);
+			bool found = (tname.CompareNoCase(dbv.ptszVal) == 0);
 			db_free(&dbv);
 			if (found)
 				return;
@@ -883,14 +875,14 @@ void SmileyCategoryListType::DeleteAccountAsCategory(PROTOACCOUNT *acc)
 	}
 
 	for (int i=0; i < m_SmileyCategories.getCount(); i++) {
-		if (tname.comparei(m_SmileyCategories[i].GetName()) == 0) {
+		if (tname.CompareNoCase(m_SmileyCategories[i].GetName()) == 0) {
 			m_SmileyCategories.remove(i);
 			break;
 		}
 	}
 }
 
-void SmileyCategoryListType::AddContactTransportAsCategory(HANDLE hContact, const bkstring& defaultFile)
+void SmileyCategoryListType::AddContactTransportAsCategory(HANDLE hContact, const CMString& defaultFile)
 {
 	char* proto = GetContactProto(hContact);
 	if (proto == NULL) return;
@@ -918,12 +910,12 @@ void SmileyCategoryListType::AddContactTransportAsCategory(HANDLE hContact, cons
 
 		mir_free(trsp);
 
-		bkstring displayName = dbv.ptszVal;
+		CMString displayName = dbv.ptszVal;
 		if (packname != NULL) {
 			char path[MAX_PATH];
 			mir_snprintf(path, sizeof(path), "Smileys\\nova\\%s.msl", packname);
 
-			bkstring paths = A2T_SM(path), patha; 
+			CMString paths = A2T_SM(path), patha; 
 			pathToAbsolute(paths, patha);
 
 			if (_taccess(patha.c_str(), 0) != 0) 
@@ -939,11 +931,11 @@ void SmileyCategoryListType::AddContactTransportAsCategory(HANDLE hContact, cons
 
 void SmileyCategoryListType::AddAllProtocolsAsCategory(void)
 {
-	bkstring displayName = TranslateT("Standard");
-	bkstring tname = _T("Standard");
+	CMString displayName = TranslateT("Standard");
+	CMString tname = _T("Standard");
 	AddCategory(tname, displayName, smcStd);
 
-	const bkstring& defaultFile = GetSmileyCategory(tname)->GetFilename();
+	const CMString& defaultFile = GetSmileyCategory(tname)->GetFilename();
 
 
 	unsigned lpcp = (unsigned)CallService(MS_LANGPACK_GETCODEPAGE, 0, 0);
@@ -959,37 +951,35 @@ void SmileyCategoryListType::AddAllProtocolsAsCategory(void)
 	for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
 		AddContactTransportAsCategory(hContact, defaultFile);
 
-	bkstring cats;
+	CMString cats;
 	opt.ReadCustomCategories(cats);
 
-	bkstring::size_type cppv = 0; 
-	for (;;)
-	{
-		bkstring::size_type cp = cats.find('#', cppv);
-		if (cp != cats.npos)
-		{
-			displayName = cats.substr(cppv, cp - cppv);
-			AddCategory(displayName, displayName, smcCustom, defaultFile);
-			cppv = cp + 1;
-		}
-		else break;
+	int cppv = 0; 
+	for (;;) {
+		int cp = cats.Find('#', cppv);
+		if (cp == -1)
+			break;
+			
+		displayName = cats.Mid(cppv, cp - cppv);
+		AddCategory(displayName, displayName, smcCustom, defaultFile);
+		cppv = cp + 1;
 	}
-	if (cppv != cats.size())
-	{
-		displayName = cats.substr(cppv, cats.size() - cppv);
+
+	if (cppv != cats.GetLength()) {
+		displayName = cats.Mid(cppv, cats.GetLength() - cppv);
 		AddCategory(displayName, displayName, smcCustom, defaultFile);
 	}
 }
 
 
-SmileyLookup::SmileyLookup(const bkstring& str, const bool regexs, const int ind, const bkstring& smpt)
+SmileyLookup::SmileyLookup(const CMString& str, const bool regexs, const int ind, const CMString& smpt)
 {
 	TCHAR msgtxt[1024];
 
 	m_ind = ind;
 	if (regexs)
 	{
-		static const bkstring testString(_T("Test String"));
+		static const CMString testString(_T("Test String"));
 		m_pattern = _TPattern::compile(str);
 		m_valid = m_pattern != NULL;
 		if (m_valid)
@@ -1016,7 +1006,7 @@ SmileyLookup::SmileyLookup(const bkstring& str, const bool regexs, const int ind
 	{
 		m_text = str;
 		m_pattern = NULL;
-		m_valid = !str.empty();
+		m_valid = !str.IsEmpty();
 	}
 }
 
@@ -1027,33 +1017,30 @@ SmileyLookup::~SmileyLookup()
 }
 
 
-void SmileyLookup::find(const bkstring& str, SmileyLocVecType& smlcur, bool firstOnly) const
+void SmileyLookup::Find(const CMString& str, SmileyLocVecType& smlcur, bool firstOnly) const
 {
 	if (!m_valid) return;
 
-	if (m_text.empty())
-	{
+	if (m_text.IsEmpty()) {
 		_TMatcher* matcher = m_pattern->createTMatcher(str);
-		while( matcher->findNextMatch())
-		{
-			bkstring::size_type st = matcher->getStartingIndex();
-			bkstring::size_type sz = matcher->getEndingIndex() - st;
-			if (sz != 0) 
-			{
+		while( matcher->findNextMatch()) {
+			int st = matcher->getStartingIndex();
+			int sz = matcher->getEndingIndex() - st;
+			if (sz != 0) {
 				smlcur.insert(new SmileyLocType(st, sz));
-				if (firstOnly && m_ind != -1) return;
+				if (firstOnly && m_ind != -1)
+					return;
 			}
 		}
 		delete matcher;
 	}
-	else
-	{
+	else {
 		const TCHAR* pos = str.c_str();
-		while( (pos = _tcsstr(pos, m_text.c_str())) != NULL )
-		{
-			smlcur.insert(new SmileyLocType(pos - str.c_str(), m_text.size()));
-			pos += m_text.size();
-			if (firstOnly && m_ind != -1) return;
+		while( (pos = _tcsstr(pos, m_text.c_str())) != NULL ) {
+			smlcur.insert(new SmileyLocType(pos - str.c_str(), m_text.GetLength()));
+			pos += m_text.GetLength();
+			if (firstOnly && m_ind != -1)
+				return;
 		}
 	}
 }
diff --git a/plugins/SmileyAdd/src/smileys.h b/plugins/SmileyAdd/src/smileys.h
index ad0eb059bc..76b0dc0f12 100644
--- a/plugins/SmileyAdd/src/smileys.h
+++ b/plugins/SmileyAdd/src/smileys.h
@@ -39,24 +39,24 @@ protected:
 	HICON m_SmileyIcon;
 	ImageBase* m_xepimg;
 
-	bkstring m_filepath;
+	CMString m_filepath;
 
 	void SetFlagsBit(unsigned flag, bool set)
 	{ if (set) m_flags |= flag; else m_flags &= ~flag; } 
 
 public:
 
-	bkstring m_TriggerText;
-	bkstring m_ToolText;
-	bkstring m_InsertText;
+	CMString m_TriggerText;
+	CMString m_ToolText;
+	CMString m_InsertText;
 
 	SmileyType(void);
 	~SmileyType();
 
-	const bkstring& GetTriggerText(void) const { return m_TriggerText; }
-	const bkstring& GetToolText(void) const { return m_ToolText; }
-	const bkstring& GetInsertText(void) const { return m_InsertText; }
-	const bkstring& GetFilePath(void) const { return m_filepath; }
+	const CMString& GetTriggerText(void) const { return m_TriggerText; }
+	const CMString& GetToolText(void) const { return m_ToolText; }
+	const CMString& GetInsertText(void) const { return m_InsertText; }
+	const CMString& GetFilePath(void) const { return m_filepath; }
 
 	bool IsHidden(void) const { return (m_flags & HiddenSmiley) != 0; }
 	bool IsRegEx(void) const { return (m_flags & RegExSmiley) != 0; }
@@ -86,7 +86,7 @@ public:
 
 	void SetImList(HIMAGELIST hImLst, long i);
 
-	bool LoadFromResource(const bkstring& file, const int index);
+	bool LoadFromResource(const CMString& file, const int index);
 	bool LoadFromImage(IStream* pStream);
 };
 
@@ -123,7 +123,7 @@ private:
 	_TPattern* m_pattern;
 
 	int m_ind;
-	bkstring m_text;
+	CMString m_text;
 	bool m_valid;
 
 public:
@@ -136,11 +136,11 @@ public:
 	typedef SMOBJLIST<SmileyLocType> SmileyLocVecType;
 
 	SmileyLookup() { m_ind = 0; m_valid = false; m_pattern = NULL; };
-	SmileyLookup(const bkstring& str, const bool regexs, const int ind, const bkstring& smpt);
+	SmileyLookup(const CMString& str, const bool regexs, const int ind, const CMString& smpt);
 	~SmileyLookup();
 
-	void find(const bkstring& str, SmileyLocVecType& smlcur, bool firstOnly) const;
-	int GetIndex(void) const { return m_ind; }
+	void Find(const CMString& str, SmileyLocVecType& smlcur, bool firstOnly) const;
+	int  GetIndex(void) const { return m_ind; }
 	bool IsValid(void) const { return m_valid; }
 };
 
@@ -154,12 +154,12 @@ public:
 	POINT selec, win;
 
 private:
-	bkstring m_Filename;  //used as identification
-	bkstring m_Name;
-	bkstring m_Author;
-	bkstring m_Date;
-	bkstring m_Version;
-	bkstring m_ButtonSmiley;
+	CMString m_Filename;  //used as identification
+	CMString m_Name;
+	CMString m_Author;
+	CMString m_Date;
+	CMString m_Version;
+	CMString m_ButtonSmiley;
 
 	HIMAGELIST m_hSmList;
 
@@ -170,11 +170,11 @@ private:
 
 	bool errorFound;
 
-	void InsertLookup(SmileyType& sml, bkstring& lk, bool first);
+	void InsertLookup(SmileyType& sml, CMString& lk, bool first);
 	void AddTriggersToSmileyLookup(void);
-	void ReplaceAllSpecials(const bkstring& Input, bkstring& Output);
-	bool LoadSmileyFileMSL(bkstring& tbuf, bool onlyInfo, bkstring& modpath);
-	bool LoadSmileyFileXEP(bkstring& tbuf, bool onlyInfo, bkstring& modpath);
+	void ReplaceAllSpecials(const CMString& Input, CMString& Output);
+	bool LoadSmileyFileMSL(CMString& tbuf, bool onlyInfo, CMString& modpath);
+	bool LoadSmileyFileXEP(CMString& tbuf, bool onlyInfo, CMString& modpath);
 
 public:
 	SmileyPackType();
@@ -183,11 +183,11 @@ public:
 	SmileyVectorType& GetSmileyList(void) { return m_SmileyList; }
 	SmileyLookupType* GetSmileyLookup(void) { return &m_SmileyLookup; }
 
-	const bkstring& GetFilename(void) const { return m_Filename; }
-	const bkstring& GetName(void) const { return m_Name; }
-	const bkstring& GetAuthor(void) const { return m_Author; }
-	const bkstring& GetDate(void) const { return m_Date; }
-	const bkstring& GetVersion(void) const { return m_Version; }
+	const CMString& GetFilename(void) const { return m_Filename; }
+	const CMString& GetName(void) const { return m_Name; }
+	const CMString& GetAuthor(void) const { return m_Author; }
+	const CMString& GetDate(void) const { return m_Date; }
+	const CMString& GetVersion(void) const { return m_Version; }
 
 	int SmileyCount(void) const { return m_SmileyList.getCount(); }
 	int VisibleSmileyCount(void) const { return m_VisibleCount; }
@@ -196,7 +196,7 @@ public:
 
 	const TCHAR* GetButtonSmiley(void) const { return m_ButtonSmiley.c_str(); }
 
-	bool LoadSmileyFile(const bkstring& filename, bool onlyInfo, bool noerr = false);
+	bool LoadSmileyFile(const CMString& filename, bool onlyInfo, bool noerr = false);
 
 	void Clear(void);
 };
@@ -213,9 +213,9 @@ private:
 public:
 	int NumberOfSmileyPacks(void) { return m_SmileyPacks.getCount(); }
 
-	bool AddSmileyPack(bkstring& filename);
+	bool AddSmileyPack(CMString& filename);
 	void ClearAndFreeAll(void);
-	SmileyPackType* GetSmileyPack(bkstring& filename);
+	SmileyPackType* GetSmileyPack(CMString& filename);
 };
 
 
@@ -232,9 +232,9 @@ typedef enum
 class SmileyCategoryType
 {
 private:
-	bkstring m_Name;
-	bkstring m_DisplayName;
-	bkstring m_Filename;     //functions as identification 
+	CMString m_Name;
+	CMString m_DisplayName;
+	CMString m_Filename;     //functions as identification 
 
 	SmcType type;
 
@@ -242,12 +242,12 @@ private:
 
 public:
 	SmileyCategoryType() { type = smcNone; m_pSmileyPackStore = NULL; };
-	SmileyCategoryType(SmileyPackListType* pSPS, const bkstring& name, 
-		const bkstring& displayName, const bkstring& defaultFilename, SmcType typ);
+	SmileyCategoryType(SmileyPackListType* pSPS, const CMString& name, 
+		const CMString& displayName, const CMString& defaultFilename, SmcType typ);
 
-	const bkstring& GetDisplayName(void) const { return m_DisplayName; }
-	const bkstring& GetName(void) const { return m_Name; }
-	const bkstring& GetFilename(void) const { return m_Filename; }
+	const CMString& GetDisplayName(void) const { return m_DisplayName; }
+	const CMString& GetName(void) const { return m_Name; }
+	const CMString& GetFilename(void) const { return m_Filename; }
 
 	bool IsCustom(void) { return type == smcCustom; }
 	bool IsProto(void)  { return type == smcProto;  }
@@ -257,10 +257,10 @@ public:
 
 	SmileyPackType* GetSmileyPack(void);
 
-	void SetFilename(bkstring& name) { m_Filename = name; }
-	void SetDisplayName(bkstring& name) { m_DisplayName = name; }
+	void SetFilename(CMString& name) { m_Filename = name; }
+	void SetDisplayName(CMString& name) { m_DisplayName = name; }
 
-	void ClearFilename(void) { m_Filename.clear(); }
+	void ClearFilename(void) { m_Filename.Empty(); }
 	void SaveSettings(void);
 
 	void Load(void);
@@ -279,19 +279,19 @@ private:
 public:  
 	void SetSmileyPackStore(SmileyPackListType* pSPS)  { m_pSmileyPackStore = pSPS; }
 
-	SmileyCategoryType* GetSmileyCategory(const bkstring& name);
+	SmileyCategoryType* GetSmileyCategory(const CMString& name);
 	SmileyCategoryType* GetSmileyCategory(unsigned index);
-	SmileyPackType* GetSmileyPack(bkstring& name);
+	SmileyPackType* GetSmileyPack(CMString& name);
 	SmileyCategoryVectorType* GetSmileyCategoryList(void) { return &m_SmileyCategories; };
 
 	int NumberOfSmileyCategories(void) { return m_SmileyCategories.getCount(); }
 
-	void AddCategory(const bkstring& name, const bkstring& displayName, SmcType typ,
-		const bkstring& defaultFilename = bkstring(_T("Smileys\\nova\\default.msl")));
-	void AddAndLoad(const bkstring& name, const bkstring& displayName);
+	void AddCategory(const CMString& name, const CMString& displayName, SmcType typ,
+		const CMString& defaultFilename = CMString(_T("Smileys\\nova\\default.msl")));
+	void AddAndLoad(const CMString& name, const CMString& displayName);
 	void AddAllProtocolsAsCategory(void); 
-	void AddAccountAsCategory(PROTOACCOUNT *acc, const bkstring& defaultFile);
-	void AddContactTransportAsCategory(HANDLE hContact, const bkstring& defaultFile);
+	void AddAccountAsCategory(PROTOACCOUNT *acc, const CMString& defaultFile);
+	void AddContactTransportAsCategory(HANDLE hContact, const CMString& defaultFile);
 
 	void ClearAndLoadAll(void);
 	void ClearAll(void) 
diff --git a/plugins/SmileyAdd/src/smltool.cpp b/plugins/SmileyAdd/src/smltool.cpp
index 6e1955332a..314a833547 100644
--- a/plugins/SmileyAdd/src/smltool.cpp
+++ b/plugins/SmileyAdd/src/smltool.cpp
@@ -203,7 +203,7 @@ void SmileyToolWindowType::InsertSmiley(void)
 		}
 		else
 		{
-			bkstring insertText;
+			CMString insertText;
 
 			if (opt.SurroundSmileyWithSpaces) insertText = ' ';
 			insertText += sml->GetInsertText();
@@ -245,7 +245,7 @@ void SmileyToolWindowType::SmileySel(int but)
 			ti.hwnd = m_hwndDialog;
 			ti.uId = (UINT_PTR)m_hwndDialog;
 
-			const bkstring& toolText = m_pSmileyPack->GetSmiley(m_CurrentHotTrack)->GetToolText();
+			const CMString& toolText = m_pSmileyPack->GetSmiley(m_CurrentHotTrack)->GetToolText();
 			ti.lpszText = const_cast<TCHAR*>(toolText.c_str()); 
 			SendMessage(m_hToolTip, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti);
 			SendMessage(m_hToolTip, TTM_ACTIVATE, TRUE, 0);
-- 
cgit v1.2.3