Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(507)

Side by Side Diff: runtime/vm/unicode.h

Issue 8333001: Implement case mapping using the Unicode default case mapping algorithm. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Renamed result string variables. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/unicode_data.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_UNICODE_H_ 5 #ifndef VM_UNICODE_H_
6 #define VM_UNICODE_H_ 6 #define VM_UNICODE_H_
7 7
8 #include "vm/allocation.h" 8 #include "vm/allocation.h"
9 #include "vm/globals.h" 9 #include "vm/globals.h"
10 10
(...skipping 15 matching lines...) Expand all
26 26
27 static void Encode(int32_t ch, char* dst); 27 static void Encode(int32_t ch, char* dst);
28 static intptr_t Encode(const String& src, char* dst, intptr_t len); 28 static intptr_t Encode(const String& src, char* dst, intptr_t len);
29 29
30 static intptr_t Decode(const char*, int32_t* ch); 30 static intptr_t Decode(const char*, int32_t* ch);
31 static bool Decode(const char* src, uint8_t* dst, intptr_t len); 31 static bool Decode(const char* src, uint8_t* dst, intptr_t len);
32 static bool Decode(const char* src, uint16_t* dst, intptr_t len); 32 static bool Decode(const char* src, uint16_t* dst, intptr_t len);
33 static bool Decode(const char* src, uint32_t* dst, intptr_t len); 33 static bool Decode(const char* src, uint32_t* dst, intptr_t len);
34 }; 34 };
35 35
36
37 class CaseMapping : AllStatic {
38 public:
39 // Maps a code point to uppercase.
40 static int32_t ToUpper(int32_t code_point) {
41 return Convert(code_point, kUppercase);
42 }
43
44 // Maps a code point to lowercase.
45 static int32_t ToLower(int32_t code_point) {
46 return Convert(code_point, kLowercase);
47 }
48
49 private:
50 // Property is a delta to the uppercase mapping.
51 static const int32_t kUppercase = 1;
52
53 // Property is a delta to the uppercase mapping.
54 static const int32_t kLowercase = 2;
55
56 // Property is an index into the exception table.
57 static const int32_t kException = 3;
58
59 // Type bit-field parameters
60 static const int32_t kTypeShift = 2;
61 static const int32_t kTypeMask = 3;
62
63 // The size of the stage 1 index.
64 // TODO(cshapiro): improve indexing so this value is unnecessary.
65 static const int kStage1Size = 261;
66
67 // The size of a stage 2 block in bytes.
68 static const int kBlockSizeLog2 = 8;
69 static const int kBlockSize = 1 << kBlockSizeLog2;
70
71 static int32_t Convert(int32_t ch, int32_t mapping) {
72 if (ch <= 0xFF) {
73 int32_t info = stage2_[ch];
74 if ((info & kTypeMask) == mapping) {
75 ch += info >> kTypeShift;
76 }
77 } else if (ch <= (kStage1Size << kBlockSizeLog2)) {
78 int16_t offset = stage1_[ch >> kBlockSizeLog2] << kBlockSizeLog2;
79 int32_t info = stage2_[offset + (ch & (kBlockSize - 1))];
80 int32_t type = info & kTypeMask;
81 if (type == mapping) {
82 ch += (info >> kTypeShift);
83 } else if (type == kException) {
84 ch += stage2_exception_[info >> kTypeShift][mapping - 1];
85 }
86 }
87 return ch;
88 }
89
90 // Index into the data array.
91 static const uint8_t stage1_[];
92
93 // Data for small code points with one mapping
94 static const int16_t stage2_[];
95
96 // Data for large code points or code points with both mappings.
97 static const int32_t stage2_exception_[][2];
98 };
99
36 } // namespace dart 100 } // namespace dart
37 101
38 #endif // VM_UNICODE_H_ 102 #endif // VM_UNICODE_H_
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/unicode_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698