Browse Source

test the remaining nfc_string member functions.

master
roker 1 week ago
parent
commit
b8df0024af
3 changed files with 27 additions and 6 deletions
  1. +12
    -5
      src/nfc.cc
  2. +2
    -1
      src/nfc.hh
  3. +13
    -0
      test/unittest_nfcstring.cc

+ 12
- 5
src/nfc.cc View File

@ -565,11 +565,18 @@ bool UTF<CharT>::is_safe_NFC_start(std::basic_string_view<CharT> s)
const CharT* begin = s.data();
const CharT* const end = s.data() + s.size();
const uint32_t u = parse(begin, end);
if(NFC_No.count(u)) return false;
if(NFC_Maybe.count(u)) return false;
return true;
try
{
const uint32_t u = parse(begin, end);
if(NFC_No.count(u)) return false;
if(NFC_Maybe.count(u)) return false;
return true;
}
catch(const utf_exception& ue)
{
throw illegal_utf(s, begin-s.data(), ue.reason());
}
}


+ 2
- 1
src/nfc.hh View File

@ -96,7 +96,8 @@ public:
/// only forward iterator. Does a backward_iterator make sense in UTF-encoded strings?
typedef typename String::const_iterator const_iterator;
static const size_t npos = String::npos;
static
constexpr size_t npos = String::npos;
explicit nfc_string(StringView src);
explicit nfc_string(String && src);


+ 13
- 0
test/unittest_nfcstring.cc View File

@ -51,6 +51,17 @@ TEST( NfcTestString, Simple )
// removal of the r-with-caron let the remaining ogonek combine with the e to U+0119 (E WITH OGONEK)
EXPECT_EQ( s.erase(11, 2).get(), "ÜberHäus\u0119" );
EXPECT_TRUE ( s.starts_with("Üb") );
EXPECT_FALSE( s.starts_with("Üx") );
EXPECT_TRUE ( s.ends_with("s\u0119") );
EXPECT_FALSE( s.ends_with("ss\u0119") );
EXPECT_EQ( s.find("Über"), 0u );
EXPECT_EQ( s.find("ber") , 2u );
EXPECT_EQ( s.find("über"), UTF8::nfc_string::npos );
EXPECT_EQ( s.find("Übel"), UTF8::nfc_string::npos );
}
@ -58,4 +69,6 @@ TEST( NfcTestString, Exceptions )
{
pEp::nfc_string s;
EXPECT_THROW( s = "Meep\xc0\x80.", pEp::illegal_utf );
EXPECT_THROW( s += '\377', pEp::illegal_utf );
}

Loading…
Cancel
Save