diff options
author | Neil <nyamatongwe@gmail.com> | 2020-04-10 14:54:02 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2020-04-10 14:54:02 +1000 |
commit | 3324fb5e20704fa2cc3985eb4a38d3862b6305fb (patch) | |
tree | 90efe1cbb0c5c41720f7c328acedb153b3b1772d /src | |
parent | e27b4f5a2cbb11d2b6ec0c8cb4deb899495df06e (diff) | |
download | scintilla-mirror-3324fb5e20704fa2cc3985eb4a38d3862b6305fb.tar.gz |
Move static functions into unnamed namespace and simplify line counting.
Diffstat (limited to 'src')
-rw-r--r-- | src/PerLine.cxx | 36 |
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); |