diff options
| -rw-r--r-- | src/Accessor.cxx | 166 | ||||
| -rw-r--r-- | src/UniConversion.cxx | 77 | ||||
| -rw-r--r-- | src/UniConversion.h | 9 | 
3 files changed, 86 insertions, 166 deletions
| diff --git a/src/Accessor.cxx b/src/Accessor.cxx deleted file mode 100644 index f080742bd..000000000 --- a/src/Accessor.cxx +++ /dev/null @@ -1,166 +0,0 @@ -// SciTE - Scintilla based Text Editor -// Accessor.cxx - rapid easy access to contents of a Scintilla -// Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org> -// The License.txt file describes the conditions under which this software may be distributed. - -#include <stdlib.h> -#include <ctype.h>  -#include <stdio.h> - -#include "Platform.h" - -#include "PropSet.h" -#include "Accessor.h" -#include "Scintilla.h" - -bool Accessor::InternalIsLeadByte(char ch) { -#if PLAT_GTK -	// TODO: support DBCS under GTK+ -	return false; -#elif PLAT_WIN  -	return IsDBCSLeadByteEx(codePage, ch); -#elif PLAT_WX  -	return false; -#endif  -} - -void Accessor::Fill(int position) { -	if (lenDoc == -1) -		lenDoc = Platform::SendScintilla(id, WM_GETTEXTLENGTH, 0, 0); -	startPos = position - slopSize; -	if (startPos + bufferSize > lenDoc) -		startPos = lenDoc - bufferSize; -	if (startPos < 0) -		startPos = 0; -	endPos = startPos + bufferSize; -	if (endPos > lenDoc) -		endPos = lenDoc; - -	TEXTRANGE tr = {{startPos, endPos}, buf}; -	Platform::SendScintilla(id, EM_GETTEXTRANGE, 0, reinterpret_cast<LPARAM>(&tr)); -} - -char Accessor::StyleAt(int position) { -	return static_cast<char>(Platform::SendScintilla( -		id, SCI_GETSTYLEAT, position, 0)); -} - -int Accessor::GetLine(int position) { -	return Platform::SendScintilla(id, EM_LINEFROMCHAR, position, 0); -} - -int Accessor::LineStart(int line) { -	return Platform::SendScintilla(id, EM_LINEINDEX, line, 0); -} - -int Accessor::LevelAt(int line) { -	return Platform::SendScintilla(id, SCI_GETFOLDLEVEL, line, 0); -} - -int Accessor::Length() {  -	if (lenDoc == -1)  -		lenDoc = Platform::SendScintilla(id, WM_GETTEXTLENGTH, 0, 0); -	return lenDoc;  -} - -int Accessor::GetLineState(int line) { -	return Platform::SendScintilla(id, SCI_GETLINESTATE, line); -} - -int Accessor::SetLineState(int line, int state) { -	return Platform::SendScintilla(id, SCI_SETLINESTATE, line, state); -} - -void StylingContext::StartAt(unsigned int start, char chMask) { -	Platform::SendScintilla(id, SCI_STARTSTYLING, start, chMask); -} - -void StylingContext::StartSegment(unsigned int pos) { -	startSeg = pos; -} - -void StylingContext::ColourTo(unsigned int pos, int chAttr) { -	// Only perform styling if non empty range -	if (pos != startSeg - 1) { -		if (pos < startSeg) { -			Platform::DebugPrintf("Bad colour positions %d - %d\n", startSeg, pos); -		} - -		if (validLen + (pos - startSeg + 1) >= bufferSize) -			Flush(); -		if (validLen + (pos - startSeg + 1) >= bufferSize) { -			// Too big for buffer so send directly -			Platform::SendScintilla(id, SCI_SETSTYLING, pos - startSeg + 1, chAttr); -		} else { -			if (chAttr != chWhile) -				chFlags = 0; -			chAttr |= chFlags; -			for (unsigned int i = startSeg; i <= pos; i++) { -				styleBuf[validLen++] = chAttr; -			} -		} -	} -	startSeg = pos+1; -} - -int StylingContext::GetLine(int position) { -	return Platform::SendScintilla(id, EM_LINEFROMCHAR, position, 0); -} - -void StylingContext::SetLevel(int line, int level) { -	Platform::SendScintilla(id, SCI_SETFOLDLEVEL, line, level); -} - -void StylingContext::Flush() { -	if (validLen > 0) { -		Platform::SendScintilla(id, SCI_SETSTYLINGEX, validLen,  -			reinterpret_cast<LPARAM>(styleBuf)); -		validLen = 0; -	} -} - -int StylingContext::IndentAmount(int line, int *flags, PFNIsCommentLeader pfnIsCommentLeader) { -	int end = Length(); -	int spaceFlags = 0; -	 -	// Determines the indentation level of the current line and also checks for consistent  -	// indentation compared to the previous line. -	// Indentation is judged consistent when the indentation whitespace of each line lines  -	// the same or the indentation of one line is a prefix of the other. -	 -	int pos = LineStart(line); -	char ch = (*this)[pos]; -	int indent = 0; -	bool inPrevPrefix = line > 0; -	int posPrev = inPrevPrefix ? LineStart(line-1) : 0; -	while ((ch == ' ' || ch == '\t') && (pos < end)) { -		if (inPrevPrefix) { -			char chPrev = (*this)[posPrev++]; -			if (chPrev == ' ' || chPrev == '\t') { -				if (chPrev != ch) -					spaceFlags |= wsInconsistent; -			} else { -				inPrevPrefix = false; -			} -		} -		if (ch == ' ') { -			spaceFlags |= wsSpace; -			indent++; -		} else {	// Tab -			spaceFlags |= wsTab; -			if (spaceFlags & wsSpace) -				spaceFlags |= wsSpaceTab; -			indent = (indent / 8 + 1) * 8; -		} -		ch = (*this)[++pos]; -	} -	 -	*flags = spaceFlags; -	indent += SC_FOLDLEVELBASE; -	// if completely empty line or the start of a comment... -	if (isspace(ch) || (pfnIsCommentLeader && (*pfnIsCommentLeader)(*this, pos, end-pos)) ) -		return indent | SC_FOLDLEVELWHITEFLAG; -	else -		return indent; -} - diff --git a/src/UniConversion.cxx b/src/UniConversion.cxx new file mode 100644 index 000000000..9306f307c --- /dev/null +++ b/src/UniConversion.cxx @@ -0,0 +1,77 @@ +// UniConversion.h - functions to handle UFT-8 and UCS-2 strings +// Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org> +// The License.txt file describes the conditions under which this software may be distributed. + +#include <stdlib.h> + +#include "UniConversion.h" + +unsigned int UTF8Length(const wchar_t *uptr, unsigned int tlen) { +	unsigned int len = 0; +	for (unsigned int i = 0; i < tlen && uptr[i]; i++) { +		unsigned int uch = uptr[i]; +		if (uch < 0x80) +			len++; +		else if (uch < 0x800) +			len+=2; +		else +			len +=3; +	} +	return len; +} + +void UTF8FromUCS2(const wchar_t *uptr, unsigned int tlen, char *putf, unsigned int len) { +	int k = 0; +	for (unsigned int i = 0; i < tlen && uptr[i]; i++) { +		unsigned int uch = uptr[i]; +		if (uch < 0x80) { +			putf[k++] = static_cast<char>(uch); +		} else if (uch < 0x800) { +			putf[k++] = static_cast<char>(0xC0 | (uch >> 6)); +			putf[k++] = static_cast<char>(0x80 | (uch & 0x3f)); +		} else { +			putf[k++] = static_cast<char>(0xE0 | (uch >> 12)); +			putf[k++] = static_cast<char>(0x80 | ((uch >> 6) & 0x3f)); +			putf[k++] = static_cast<char>(0x80 | (uch & 0x3f)); +		} +	} +	putf[len] = '\0'; +} + +unsigned int UCS2Length(const char *s, unsigned int len) { +	unsigned int ulen = 0; +	for (unsigned int i=0;i<len;i++) { +		unsigned char ch = static_cast<unsigned char>(s[i]); +		if ((ch < 0x80) || (ch > (0x80 + 0x40))) +			ulen++; +	} +	return ulen; +} + +unsigned int UCS2FromUTF8(const char *s, unsigned int len, wchar_t *tbuf, unsigned int tlen) { +#ifdef USE_API +	return ::MultiByteToWideChar(CP_UTF8, 0, s, len, tbuf, tlen); +#else  +	unsigned int ui=0; +	const unsigned char *us = reinterpret_cast<const unsigned char *>(s); +	unsigned int i=0; +	while ((i<len) && (ui<tlen)) { +		unsigned char ch = us[i++]; +		if (ch < 0x80) { +			tbuf[ui] = ch; +		} else if (ch < 0x80 + 0x40 + 0x20) { +			tbuf[ui] = static_cast<wchar_t>((ch & 0x1F) << 6); +			ch = us[i++]; +			tbuf[ui] = static_cast<wchar_t>(tbuf[ui] + (ch & 0x7F)); +		} else { +			tbuf[ui] = static_cast<wchar_t>((ch & 0xF) << 12); +			ch = us[i++]; +			tbuf[ui] = static_cast<wchar_t>(tbuf[ui] + ((ch & 0x7F) << 6)); +			ch = us[i++]; +			tbuf[ui] = static_cast<wchar_t>(tbuf[ui] + (ch & 0x7F)); +		} +		ui++; +	} +	return ui; +#endif +} diff --git a/src/UniConversion.h b/src/UniConversion.h new file mode 100644 index 000000000..cace497c4 --- /dev/null +++ b/src/UniConversion.h @@ -0,0 +1,9 @@ +// UniConversion.h - functions to handle UFT-8 and UCS-2 strings +// Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org> +// The License.txt file describes the conditions under which this software may be distributed. + +unsigned int UTF8Length(const wchar_t *uptr, unsigned int tlen); +void UTF8FromUCS2(const wchar_t *uptr, unsigned int tlen, char *putf, unsigned int len); +unsigned int UCS2Length(const char *s, unsigned int len); +unsigned int UCS2FromUTF8(const char *s, unsigned int len, wchar_t *tbuf, unsigned int tlen); + | 
