aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/PerLine.cxx36
1 files changed, 15 insertions, 21 deletions
diff --git a/src/PerLine.cxx b/src/PerLine.cxx
index aa85faa28..48090343a 100644
--- a/src/PerLine.cxx
+++ b/src/PerLine.cxx
@@ -305,31 +305,30 @@ Sci::Line LineState::GetMaxLineState() const noexcept {
return lineStates.Length();
}
-static int NumberLines(const char *text) noexcept {
- if (text) {
- int newLines = 0;
- while (*text) {
- if (*text == '\n')
- newLines++;
- text++;
- }
- return newLines+1;
- } else {
- return 0;
- }
-}
-
// Each allocated LineAnnotation is a char array which starts with an AnnotationHeader
// and then has text and optional styles.
-static constexpr int IndividualStyles = 0x100;
-
struct AnnotationHeader {
short style; // Style IndividualStyles implies array of styles
short lines;
int length;
};
+namespace {
+
+constexpr int IndividualStyles = 0x100;
+
+size_t NumberLines(std::string_view sv) {
+ return std::count(sv.begin(), sv.end(), '\n') + 1;
+}
+
+std::unique_ptr<char[]>AllocateAnnotation(size_t length, int style) {
+ const size_t len = sizeof(AnnotationHeader) + length + ((style == IndividualStyles) ? length : 0);
+ return std::make_unique<char[]>(len);
+}
+
+}
+
LineAnnotation::~LineAnnotation() {
}
@@ -379,11 +378,6 @@ const unsigned char *LineAnnotation::Styles(Sci::Line line) const noexcept {
return nullptr;
}
-static std::unique_ptr<char[]>AllocateAnnotation(size_t length, int style) {
- const size_t len = sizeof(AnnotationHeader) + length + ((style == IndividualStyles) ? length : 0);
- return std::make_unique<char[]>(len);
-}
-
void LineAnnotation::SetText(Sci::Line line, const char *text) {
if (text && (line >= 0)) {
annotations.EnsureLength(line+1);