From d2081b8381a0486c3dfdbfe26ed7fabab2f303b7 Mon Sep 17 00:00:00 2001 From: ntrifunovic Date: Thu, 25 Oct 2007 22:12:22 +0000 Subject: [PATCH] Added peek_next git-svn-id: http://svn.code.sf.net/p/utfcpp/code@82 a809a056-fc17-0410-9590-b4f493f8b08e --- v2_0/source/utf8/checked.h | 6 ++++++ v2_0/source/utf8/unchecked.h | 7 +++++++ v2_0/test_drivers/smoke_test/test.cpp | 12 +++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/v2_0/source/utf8/checked.h b/v2_0/source/utf8/checked.h index dc342ff..5670c19 100644 --- a/v2_0/source/utf8/checked.h +++ b/v2_0/source/utf8/checked.h @@ -152,6 +152,12 @@ namespace utf8 return cp; } + template + uint32_t peek_next(octet_iterator it, octet_iterator end) + { + return next(it, end); + } + template uint32_t prior(octet_iterator& it, octet_iterator start) { diff --git a/v2_0/source/utf8/unchecked.h b/v2_0/source/utf8/unchecked.h index 2277d28..4009ceb 100644 --- a/v2_0/source/utf8/unchecked.h +++ b/v2_0/source/utf8/unchecked.h @@ -56,6 +56,7 @@ namespace utf8 } return result; } + template uint32_t next(octet_iterator& it) { @@ -87,6 +88,12 @@ namespace utf8 return cp; } + template + uint32_t peek_next(octet_iterator it) + { + return next(it); + } + template uint32_t prior(octet_iterator& it) { diff --git a/v2_0/test_drivers/smoke_test/test.cpp b/v2_0/test_drivers/smoke_test/test.cpp index c50e136..f454549 100644 --- a/v2_0/test_drivers/smoke_test/test.cpp +++ b/v2_0/test_drivers/smoke_test/test.cpp @@ -22,7 +22,6 @@ int main() end = append(0x10346, u); assert (u[0] == 0xf0 && u[1] == 0x90 && u[2] == 0x8d && u[3] == 0x86 && u[4] == 0); - //next char* twochars = "\xe6\x97\xa5\xd1\x88"; @@ -43,6 +42,12 @@ int main() assert (cp == 0x0448); assert (w == threechars + 9); + //peek_next + char* const cw = twochars; + cp = peek_next(cw, cw + 6); + assert (cp == 0x65e5); + assert (cw == twochars); + //prior w = twochars + 3; cp = prior (w, twochars); @@ -197,6 +202,11 @@ int main() assert (cp == 0x0448); assert (w == threechars + 9); + //peek_next + cp = unchecked::peek_next(cw); + assert (cp == 0x65e5); + assert (cw == twochars); + //previous (calls prior internally)