spiegel-keyman/windows/src/support/xstringtest/XString.cpp
Marc Durdin b65b982584 Keyman Desktop and Keyman Developer open source 10.0 alpha seed (#121)
* Keyman for Windows 10.0 Open Source

* Squashed 'windows/src/ext/jedi/jedi/' content from commit f444ad2

git-subtree-dir: windows/src/ext/jedi/jedi
git-subtree-split: f444ad2da4693851e523f1ea6bd541f701904c24

* Squashed 'windows/src/ext/jedi/jcl/' content from commit d63d3c9fd

git-subtree-dir: windows/src/ext/jedi/jcl
git-subtree-split: d63d3c9fd9ff84efdd8159084ec6a60313644243

* Squashed 'windows/src/ext/jedi/jvcl/' content from commit bee19f3b4

git-subtree-dir: windows/src/ext/jedi/jvcl
git-subtree-split: bee19f3b46909fde2fa92c06cd2706f41d99f6c3

* Add required .res files

* Add required .res files

* Add docbook files (forced)

* Add required libxslt

* Add required jedi files

* Add installation files

* Tweak .gitignore for open

* CI

* Remove KMW from Developer source (#122)

* Remove KMW from Developer source (copies during build)

* Remove KMW from Developer source (copies during build)

* Remove KMW from Developer source (copies during build)

* Fixup release build and copy license, readme from kmw during build

* Remove obsolete build help documentation

* Keyman Engine 10 on Windows regression for shift states (#129)

* Improve #128 -- cleaner debug messages

* Fixes #127, shift state now resets correctly; and more work for #128

* Fixes #130 (#131)
2017-07-25 10:53:06 +07:00

165 lines
2.7 KiB
C++

#include <windows.h>
struct XChar
{
XCharType CharType;
union
{
DWORD WideChar;
struct { WORD n1, n2; }
}
};
class XString
{
private:
WCHAR *FBase;
int BaseLength;
void GetXChar(WCHAR *p, XChar *ch);
WCHAR GetWChar(WCHAR *p);
public:
/* functions starting with Base return underlying buffer information */
XString();
XString(XString *source);
XString(WCHAR *source);
void Set(XString *source);
void Set(WCHAR *source);
void Clear();
int Length();
int BaseLength();
void CharAt(int XPos, XChar *ch);
WCHAR CharAt(int XPos);
int IndexOf(XChar *ch);
int IndexOf(WCHAR ch);
void Insert(XString *str, int XPos);
void Insert(WCHAR *str, int XPos);
void Insert(XChar *ch, int XPos);
void Insert(WCHAR ch, int XPos);
void Append(XString *str);
void Append(WCHAR *str);
void Append(XChar *ch);
void Append(WCHAR ch);
void Delete(int XPos, int XLen);
const WCHAR *Base();
};
XString::XString()
{
FBase = NULL;
}
XString::XString(XString *source)
{
Set(source);
}
XString::XString(WCHAR *source)
{
Set(source);
}
void XString::Set(XString *source)
{
Clear();
FBase = new WCHAR[source->BaseLength()+1];
if(FBase) wcscpy(FBase, source->FBase);
}
void XString::Set(WCHAR *source)
{
Clear();
FBase = new WCHAR[wcslen(source)+1];
if(FBase) wcscpy(FBase, source);
}
void XString::Clear()
{
if(FBase) delete FBase;
FBase = NULL;
}
int XString::Length()
{
if(!FBase) return 0;
WCHAR *p;
int i;
for(i = 0, p = FBase; *p; p=incxstr(p), i++);
return i;
}
int XString::BaseLength()
{
if(!FBase) return 0;
return wcslen(FBase);
}
void XString::CharAt(int XPos, XChar *ch)
{
ch->CharType = ctNone;
if(!FBase) return;
WCHAR *p;
int i;
for(i = 0, p = FBase; *p && i < XPos; p=incxstr(p), i++);
if(i < XPos) return;
GetXChar(p, ch);
}
WCHAR XString::CharAt(int XPos)
{
if(!FBase) return 0;
WCHAR *p;
int i;
for(i = 0, p = FBase; *p && i < XPos; p=incxstr(p), i++);
if(i < XPos) return 0;
return GetWChar(p);
}
int XString::IndexOf(XChar *ch)
{
if(!FBase) return -1;
WCHAR *p;
int i;
for(i = 0, p = FBase; *p && !IsEqualChar(p, ch); p=incxstr(p), i++);
if(!*p) return -1;
return i;
}
int XString::IndexOf(WCHAR ch)
{
if(!FBase) return -1;
WCHAR *p;
int i;
for(i = 0, p = FBase; *p && *p != ch; p=incxstr(p), i++);
if(!*p) return -1;
return i;
}
void XString::Insert(XString *str, int XPos)
{
}
void XString::Insert(WCHAR *str, int XPos);
void XString::Insert(XChar *ch, int XPos);
void XString::Insert(WCHAR ch, int XPos);
void XString::Append(XString *str);
void XString::Append(WCHAR *str);
void XString::Append(XChar *ch);
void XString::Append(WCHAR ch);
void XString::Delete(int XPos, int XLen);
const WCHAR *Base();
/* Private functions */
void GetXChar(WCHAR *p, XChar *ch);
WCHAR GetWChar(WCHAR *p);