From 8fef8689296bfe491cbf54426ac468035152a94b Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 7 Mar 2010 22:47:25 -0500 Subject: Added find() and operator[] to unistring --- src/unistring.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/unistring.h') diff --git a/src/unistring.h b/src/unistring.h index 5413ef14..d42f2b28 100644 --- a/src/unistring.h +++ b/src/unistring.h @@ -55,6 +55,8 @@ namespace ledger { class unistring { public: + static const std::size_t npos = static_cast(-1); + std::vector utf32chars; unistring() { @@ -96,6 +98,23 @@ public: return utf8result; } + + std::size_t find(const boost::uint32_t __s, std::size_t __pos = 0) const { + std::size_t idx = 0; + foreach (const boost::uint32_t& ch, utf32chars) { + if (idx >= __pos && ch == __s) + return idx; + idx++; + } + return npos; + } + + boost::uint32_t& operator[](const std::size_t index) { + return utf32chars[index]; + } + const boost::uint32_t& operator[](const std::size_t index) const { + return utf32chars[index]; + } }; inline void justify(std::ostream& out, -- cgit v1.2.3