File: system-utfcpp.diff

package info (click to toggle)
freespace2 24.2.0%2Brepack-3
  • links: PTS, VCS
  • area: non-free
  • in suites: sid
  • size: 43,740 kB
  • sloc: cpp: 595,005; ansic: 21,741; python: 1,174; sh: 457; makefile: 243; xml: 181
file content (41 lines) | stat: -rw-r--r-- 1,358 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Description: extract a custom function found in the bundled utfcpp copy
 Allows us to build the code with libutfcpp-dev
Origin: commit:43e540cc4c193211d1d7ea474d8f864cc3c67d95
Forwarded: not-needed
--- a/code/utils/unicode.cpp
+++ b/code/utils/unicode.cpp
@@ -5,6 +5,24 @@
 
 namespace unicode {
 
+	inline size_t encoded_width(uint32_t cp)
+	{
+		if (!utf8::internal::is_code_point_valid(cp))
+			throw utf8::invalid_code_point(cp);
+
+		if (cp < 0x80)                        // one octet
+			return 1;
+		else if (cp < 0x800) {                // two octets
+			return 2;
+		}
+		else if (cp < 0x10000) {              // three octets
+			return 3;
+		}
+		else {                                // four octets
+			return 4;
+		}
+	}
+
 text_iterator::text_iterator(const char* in_current_byte, const char* in_range_start_byte, const char* in_range_end_byte) :
 	current_byte(in_current_byte), range_end_byte(in_range_end_byte), range_start_byte(in_range_start_byte) {
 	if (range_end_byte == nullptr) {
@@ -143,7 +161,7 @@ text_iterator codepoint_range::end() {
 size_t encoded_size(codepoint_t cp) {
 	if (Unicode_text_mode) {
 		try {
-			return utf8::encoded_width(cp);
+			return unicode::encoded_width(cp);
 		} catch(const std::exception& e) {
 			Error(LOCATION,
 				  "Exception while computing encoded size of Unicode code point %" PRIu32 ": %s",