summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2017-04-23 12:47:26 +0100
committerMaxime Coste <mawww@kakoune.org>2017-04-23 12:47:26 +0100
commite264d189eb43710ee542b71ba845f8b44b693e12 (patch)
tree4ab61909cc91f677173d3453a22fde520edf00ee /src
parentcaed8a55c7a5ac2754641769e1f603482886d5f1 (diff)
Add noexcept specifiers to unicode and utf8 functions
Diffstat (limited to 'src')
-rw-r--r--src/unicode.hh26
-rw-r--r--src/utf8.hh31
2 files changed, 30 insertions, 27 deletions
diff --git a/src/unicode.hh b/src/unicode.hh
index 98c69c30..eade3510 100644
--- a/src/unicode.hh
+++ b/src/unicode.hh
@@ -12,17 +12,17 @@ namespace Kakoune
using Codepoint = char32_t;
-inline bool is_eol(Codepoint c)
+inline bool is_eol(Codepoint c) noexcept
{
return c == '\n';
}
-inline bool is_horizontal_blank(Codepoint c)
+inline bool is_horizontal_blank(Codepoint c) noexcept
{
return c == ' ' or c == '\t';
}
-inline bool is_blank(Codepoint c)
+inline bool is_blank(Codepoint c) noexcept
{
return c == ' ' or c == '\t' or c == '\n';
}
@@ -30,28 +30,28 @@ inline bool is_blank(Codepoint c)
enum WordType { Word, WORD };
template<WordType word_type = Word>
-inline bool is_word(Codepoint c)
+inline bool is_word(Codepoint c) noexcept
{
return c == '_' or iswalnum((wchar_t)c);
}
template<>
-inline bool is_word<WORD>(Codepoint c)
+inline bool is_word<WORD>(Codepoint c) noexcept
{
return not is_blank(c);
}
-inline bool is_punctuation(Codepoint c)
+inline bool is_punctuation(Codepoint c) noexcept
{
return not (is_word(c) or is_blank(c));
}
-inline bool is_basic_alpha(Codepoint c)
+inline bool is_basic_alpha(Codepoint c) noexcept
{
return (c >= 'a' and c <= 'z') or (c >= 'A' and c <= 'Z');
}
-inline ColumnCount codepoint_width(Codepoint c)
+inline ColumnCount codepoint_width(Codepoint c) noexcept
{
return c == '\n' ? 1 : wcwidth((wchar_t)c);
}
@@ -65,7 +65,7 @@ enum class CharCategories
};
template<WordType word_type = Word>
-inline CharCategories categorize(Codepoint c)
+inline CharCategories categorize(Codepoint c) noexcept
{
if (is_eol(c))
return CharCategories::EndOfLine;
@@ -76,11 +76,11 @@ inline CharCategories categorize(Codepoint c)
return CharCategories::Punctuation;
}
-inline Codepoint to_lower(Codepoint cp) { return towlower((wchar_t)cp); }
-inline Codepoint to_upper(Codepoint cp) { return towupper((wchar_t)cp); }
+inline Codepoint to_lower(Codepoint cp) noexcept { return towlower((wchar_t)cp); }
+inline Codepoint to_upper(Codepoint cp) noexcept { return towupper((wchar_t)cp); }
-inline char to_lower(char c) { return c >= 'A' and c <= 'Z' ? c - 'A' + 'a' : c; }
-inline char to_upper(char c) { return c >= 'a' and c <= 'z' ? c - 'a' + 'A' : c; }
+inline char to_lower(char c) noexcept { return c >= 'A' and c <= 'Z' ? c - 'A' + 'a' : c; }
+inline char to_upper(char c) noexcept { return c >= 'a' and c <= 'z' ? c - 'a' + 'A' : c; }
}
diff --git a/src/utf8.hh b/src/utf8.hh
index 34cecc81..68d0b48d 100644
--- a/src/utf8.hh
+++ b/src/utf8.hh
@@ -15,12 +15,12 @@ namespace utf8
template<typename Iterator>
[[gnu::always_inline]]
-inline char read(Iterator& it) { char c = *it; ++it; return c; }
+inline char read(Iterator& it) noexcept { char c = *it; ++it; return c; }
// return true if it points to the first byte of a (either single or
// multibyte) character
[[gnu::always_inline]]
-inline bool is_character_start(char c)
+inline bool is_character_start(char c) noexcept
{
return (c & 0xC0) != 0x80;
}
@@ -35,7 +35,7 @@ struct Assert
struct Pass
{
- Codepoint operator()(Codepoint cp) const { return cp; }
+ Codepoint operator()(Codepoint cp) const noexcept { return cp; }
};
}
@@ -45,6 +45,7 @@ struct Pass
template<typename InvalidPolicy = utf8::InvalidPolicy::Pass,
typename Iterator>
Codepoint read_codepoint(Iterator& it, const Iterator& end)
+ noexcept(noexcept(InvalidPolicy{}(0)))
{
if (it == end)
return InvalidPolicy{}(-1);
@@ -84,12 +85,14 @@ Codepoint read_codepoint(Iterator& it, const Iterator& end)
template<typename InvalidPolicy = utf8::InvalidPolicy::Pass,
typename Iterator>
Codepoint codepoint(Iterator it, const Iterator& end)
+ noexcept(noexcept(read_codepoint<InvalidPolicy>(it, end)))
{
- return read_codepoint(it, end);
+ return read_codepoint<InvalidPolicy>(it, end);
}
template<typename InvalidPolicy = utf8::InvalidPolicy::Pass>
ByteCount codepoint_size(char byte)
+ noexcept(noexcept(InvalidPolicy{}(0)))
{
if ((byte & 0x80) == 0) // 0xxxxxxx
return 1;
@@ -123,7 +126,7 @@ inline ByteCount codepoint_size(Codepoint cp)
}
template<typename Iterator>
-void to_next(Iterator& it, const Iterator& end)
+void to_next(Iterator& it, const Iterator& end) noexcept
{
if (it != end)
++it;
@@ -133,7 +136,7 @@ void to_next(Iterator& it, const Iterator& end)
// returns an iterator to next character first byte
template<typename Iterator>
-Iterator next(Iterator it, const Iterator& end)
+Iterator next(Iterator it, const Iterator& end) noexcept
{
to_next(it, end);
return it;
@@ -142,7 +145,7 @@ Iterator next(Iterator it, const Iterator& end)
// returns it's parameter if it points to a character first byte,
// or else returns next character first byte
template<typename Iterator>
-Iterator finish(Iterator it, const Iterator& end)
+Iterator finish(Iterator it, const Iterator& end) noexcept
{
while (it != end and (*(it) & 0xC0) == 0x80)
++it;
@@ -150,7 +153,7 @@ Iterator finish(Iterator it, const Iterator& end)
}
template<typename Iterator>
-void to_previous(Iterator& it, const Iterator& begin)
+void to_previous(Iterator& it, const Iterator& begin) noexcept
{
if (it != begin)
--it;
@@ -159,7 +162,7 @@ void to_previous(Iterator& it, const Iterator& begin)
}
// returns an iterator to the previous character first byte
template<typename Iterator>
-Iterator previous(Iterator it, const Iterator& begin)
+Iterator previous(Iterator it, const Iterator& begin) noexcept
{
to_previous(it, begin);
return it;
@@ -169,7 +172,7 @@ Iterator previous(Iterator it, const Iterator& begin)
// dth character after (or before if d < 0) the character
// pointed by it
template<typename Iterator>
-Iterator advance(Iterator it, const Iterator& end, CharCount d)
+Iterator advance(Iterator it, const Iterator& end, CharCount d) noexcept
{
if (it == end)
return it;
@@ -191,7 +194,7 @@ Iterator advance(Iterator it, const Iterator& end, CharCount d)
// character at the dth column after (or before if d < 0)
// the character pointed by it
template<typename Iterator>
-Iterator advance(Iterator it, const Iterator& end, ColumnCount d)
+Iterator advance(Iterator it, const Iterator& end, ColumnCount d) noexcept
{
if (it == end)
return it;
@@ -220,7 +223,7 @@ Iterator advance(Iterator it, const Iterator& end, ColumnCount d)
// returns the character count between begin and end
template<typename Iterator>
-CharCount distance(Iterator begin, const Iterator& end)
+CharCount distance(Iterator begin, const Iterator& end) noexcept
{
CharCount dist = 0;
@@ -234,7 +237,7 @@ CharCount distance(Iterator begin, const Iterator& end)
// returns the column count between begin and end
template<typename Iterator>
-ColumnCount column_distance(Iterator begin, const Iterator& end)
+ColumnCount column_distance(Iterator begin, const Iterator& end) noexcept
{
ColumnCount dist = 0;
@@ -245,7 +248,7 @@ ColumnCount column_distance(Iterator begin, const Iterator& end)
// returns an iterator to the first byte of the character it is into
template<typename Iterator>
-Iterator character_start(Iterator it, const Iterator& begin)
+Iterator character_start(Iterator it, const Iterator& begin) noexcept
{
while (it != begin and not is_character_start(*it))
--it;