aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Document.cxx36
-rw-r--r--src/Document.h2
2 files changed, 38 insertions, 0 deletions
diff --git a/src/Document.cxx b/src/Document.cxx
index a44a51f12..7d34dace1 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -787,6 +787,27 @@ int SCI_METHOD Document::GetRelativePosition(int positionStart, int characterOff
return pos;
}
+int Document::GetRelativePositionUTF16(int positionStart, int characterOffset) const {
+ int pos = positionStart;
+ if (dbcsCodePage) {
+ const int increment = (characterOffset > 0) ? 1 : -1;
+ while (characterOffset != 0) {
+ const int posNext = NextPosition(pos, increment);
+ if (posNext == pos)
+ return INVALID_POSITION;
+ if (abs(pos-posNext) > 3) // 4 byte character = 2*UTF16.
+ characterOffset -= increment;
+ pos = posNext;
+ characterOffset -= increment;
+ }
+ } else {
+ pos = positionStart + characterOffset;
+ if ((pos < 0) || (pos > Length()))
+ return INVALID_POSITION;
+ }
+ return pos;
+}
+
int SCI_METHOD Document::GetCharacterAndWidth(int position, int *pWidth) const {
int character;
int bytesInCharacter = 1;
@@ -1308,6 +1329,21 @@ int Document::CountCharacters(int startPos, int endPos) const {
return count;
}
+int Document::CountUTF16(int startPos, int endPos) const {
+ startPos = MovePositionOutsideChar(startPos, 1, false);
+ endPos = MovePositionOutsideChar(endPos, -1, false);
+ int count = 0;
+ int i = startPos;
+ while (i < endPos) {
+ count++;
+ const int next = NextPosition(i, 1);
+ if ((next - i) > 3)
+ count++;
+ i = next;
+ }
+ return count;
+}
+
int Document::FindColumn(int line, int column) {
int position = LineStart(line);
if ((line >= 0) && (line < LinesTotal())) {
diff --git a/src/Document.h b/src/Document.h
index e808bb37f..5e66dc2b6 100644
--- a/src/Document.h
+++ b/src/Document.h
@@ -279,6 +279,7 @@ public:
int NextPosition(int pos, int moveDir) const;
bool NextCharacter(int &pos, int moveDir) const; // Returns true if pos changed
int SCI_METHOD GetRelativePosition(int positionStart, int characterOffset) const;
+ int GetRelativePositionUTF16(int positionStart, int characterOffset) const;
int SCI_METHOD GetCharacterAndWidth(int position, int *pWidth) const;
int SCI_METHOD CodePage() const;
bool SCI_METHOD IsDBCSLeadByte(char ch) const;
@@ -322,6 +323,7 @@ public:
int GetLineIndentPosition(int line) const;
int GetColumn(int position);
int CountCharacters(int startPos, int endPos) const;
+ int CountUTF16(int startPos, int endPos) const;
int FindColumn(int line, int column);
void Indent(bool forwards, int lineBottom, int lineTop);
static std::string TransformLineEnds(const char *s, size_t len, int eolModeWanted);