aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/utils/textutils.cpp
diff options
context:
space:
mode:
authorIvan Donchevskii <[email protected]>2018-10-11 14:11:43 +0200
committerIvan Donchevskii <[email protected]>2018-10-17 07:16:04 +0000
commitcafd5ced1ab02d79e3765f059b66c6b3b6533e73 (patch)
tree1e717e2ee9db895edb5f9833609aeeb7c0532640 /src/libs/utils/textutils.cpp
parent6f73b3b175086f948eee6b3097fa50aa0a52ab53 (diff)
Clang: Significantly improve ClangFormat plugin usability
What's new: 1. New LibFormat option is used to prevent lines shrink, which allows to drop most of tricks used before for that purpose. 2. Cached UTF-8 source code is used to improve performance 3. Improved error handling. 4. Slightly improved UI. Change-Id: I4605200fa103167369a40650b2e1ad2c61e8133b Reviewed-by: Marco Bubke <[email protected]>
Diffstat (limited to 'src/libs/utils/textutils.cpp')
-rw-r--r--src/libs/utils/textutils.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libs/utils/textutils.cpp b/src/libs/utils/textutils.cpp
index 192c68bcbd3..c05e6cce84e 100644
--- a/src/libs/utils/textutils.cpp
+++ b/src/libs/utils/textutils.cpp
@@ -140,5 +140,20 @@ QTextCursor wordStartCursor(const QTextCursor &textCursor)
return cursor;
}
+int utf8NthLineOffset(const QTextDocument *textDocument, const QByteArray &buffer, int line)
+{
+ if (textDocument->characterCount() == buffer.size() + 1)
+ return textDocument->findBlockByNumber(line - 1).position();
+
+ int pos = 0;
+ for (int count = 0; count < line - 1; ++count) {
+ pos = buffer.indexOf('\n', pos);
+ if (pos == -1)
+ return -1;
+ ++pos;
+ }
+ return pos;
+}
+
} // Text
} // Utils