Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Unicode.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2013, The Cinder Project
3  All rights reserved.
4 
5  This code is designed for use with the Cinder C++ library, http://libcinder.org
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
8  the following conditions are met:
9 
10  * Redistributions of source code must retain the above copyright notice, this list of conditions and
11  the following disclaimer.
12  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
13  the following disclaimer in the documentation and/or other materials provided with the distribution.
14 
15  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
16  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
19  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22  POSSIBILITY OF SUCH DAMAGE.
23 */
24 
25 #pragma once
26 
27 #include "cinder/Cinder.h"
28 #include "cinder/Function.h"
29 
30 #include <string>
31 
32 namespace cinder {
33 
34 std::u16string toUtf16( const char *utf8Str, size_t lengthInBytes = 0 );
35 std::u16string toUtf16( const std::string &utf8Str );
36 std::u32string toUtf32( const char *utf8Str, size_t lengthInBytes = 0 );
37 std::u32string toUtf32( const std::string &utf8Str );
38 
39 std::string toUtf8( const char16_t *utf16Str, size_t lengthInBytes = 0 );
40 std::string toUtf8( const std::u16string &utf16Str );
41 
42 std::string toUtf8( const char32_t *utf32str, size_t lengthInBytes = 0 );
43 std::string toUtf8( const std::u32string &utf32Str );
44 
45 std::u16string toUtf16( const std::u32string &utf32str );
46 std::u32string toUtf32( const std::u16string &utf16str );
47 
49 size_t stringLengthUtf8( const char *str, size_t lengthInBytes = 0 );
51 uint32_t nextCharUtf8( const char *str, size_t *inOutByte, size_t lengthInBytes = 0 );
53 size_t advanceCharUtf8( const char *str, size_t numChars, size_t lengthInBytes = 0 );
54 
55 void lineBreakUtf8( const char *str, const std::function<bool(const char *, size_t)> &measureFn, const std::function<void(const char *,size_t)> &lineProcessFn );
56 
59 
61 void calcLinebreaksUtf8( const char *str, std::vector<uint8_t> *resultBreaks );
62 
64 void calcLinebreaksUtf8( const char *str, size_t strLength, std::vector<uint8_t> *resultBreaks );
65 
67 void calcLinebreaksUtf16( const uint16_t *str, std::vector<uint8_t> *resultBreaks );
68 
70 void calcLinebreaksUtf16( const uint16_t *str, size_t strLength, std::vector<uint8_t> *resultBreaks );
71 
72 }
Definition: Unicode.h:58
GLsizei const GLchar ** string
Definition: GLee.h:2427
size_t stringLengthUtf8(const char *str, size_t lengthInBytes=0)
Returns the number of characters (not bytes) in the the UTF-8 string str. Optimize operation by suppl...
Definition: Unicode.cpp:149
void lineBreakUtf8(const char *str, const std::function< bool(const char *, size_t)> &measureFn, const std::function< void(const char *, size_t)> &lineProcessFn)
Definition: Unicode.cpp:237
std::u16string toUtf16(const char *utf8Str, size_t lengthInBytes=0)
Definition: Unicode.cpp:75
Definition: Unicode.h:58
size_t advanceCharUtf8(const char *str, size_t numChars, size_t lengthInBytes=0)
Returns the index in bytes of the next character in str, advanced by numChars characters. Optimize operation by supplying a non-default lengthInBytes of str.
Definition: Unicode.cpp:167
Definition: Unicode.h:58
std::u32string toUtf32(const char *utf8Str, size_t lengthInBytes=0)
Definition: Unicode.cpp:92
void calcLinebreaksUtf16(const uint16_t *str, std::vector< uint8_t > *resultBreaks)
Sets resultBreaks to be of the same length as the null-terminated UTF-16 string str with the values e...
Definition: Unicode.cpp:318
uint32_t nextCharUtf8(const char *str, size_t *inOutByte, size_t lengthInBytes=0)
Returns the UTF-32 code point of the next character in str, relative to the byte inOutByte. Increments inOutByte to be the first byte of the next character. Optimize operation by supplying a non-default lengthInBytes of str.
Definition: Unicode.cpp:160
Definition: Unicode.h:58
UnicodeBreaks
Values returned by calcBreaksUtf8 and calcBreaksUtf16.
Definition: Unicode.h:58
void calcLinebreaksUtf8(const char *str, std::vector< uint8_t > *resultBreaks)
Sets resultBreaks to be of the same length as the null-terminated UTF-8 string str with the values en...
Definition: Unicode.cpp:305
std::string toUtf8(const char16_t *utf16Str, size_t lengthInBytes=0)
Definition: Unicode.cpp:109