Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(396)

Side by Side Diff: src/pkg/unicode/letter.go

Issue 4526095: code review 4526095: unicode: add the first few property tests for printing. (Closed)
Patch Set: diff -r 88bcc11652b9 https://go.googlecode.com/hg/ Created 13 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // Package unicode provides data and functions to test some properties of 5 // Package unicode provides data and functions to test some properties of
6 // Unicode code points. 6 // Unicode code points.
7 package unicode 7 package unicode
8 8
9 const ( 9 const (
10 MaxRune = 0x10FFFF // Maximum valid Unicode code point. 10 MaxRune = 0x10FFFF // Maximum valid Unicode code point.
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 if len(r16) > 0 && rune <= int(r16[len(r16)-1].Hi) { 139 if len(r16) > 0 && rune <= int(r16[len(r16)-1].Hi) {
140 return is16(r16, uint16(rune)) 140 return is16(r16, uint16(rune))
141 } 141 }
142 r32 := rangeTab.R32 142 r32 := rangeTab.R32
143 if len(r32) > 0 && rune >= int(r32[0].Lo) { 143 if len(r32) > 0 && rune >= int(r32[0].Lo) {
144 return is32(r32, uint32(rune)) 144 return is32(r32, uint32(rune))
145 } 145 }
146 return false 146 return false
147 } 147 }
148 148
149 // IsUpper reports whether the rune is an upper case letter. 149 // IsUpper reports whether the rune is an upper case letter.
rsc 2011/06/03 05:29:30 is the plan to use the table for these too?
150 func IsUpper(rune int) bool { 150 func IsUpper(rune int) bool {
151 if rune < 0x80 { // quick ASCII check 151 if rune < 0x80 { // quick ASCII check
152 return 'A' <= rune && rune <= 'Z' 152 return 'A' <= rune && rune <= 'Z'
153 } 153 }
154 return Is(Upper, rune) 154 return Is(Upper, rune)
155 } 155 }
156 156
157 // IsLower reports whether the rune is a lower case letter. 157 // IsLower reports whether the rune is a lower case letter.
158 func IsLower(rune int) bool { 158 func IsLower(rune int) bool {
159 if rune < 0x80 { // quick ASCII check 159 if rune < 0x80 { // quick ASCII check
160 return 'a' <= rune && rune <= 'z' 160 return 'a' <= rune && rune <= 'z'
161 } 161 }
162 return Is(Lower, rune) 162 return Is(Lower, rune)
163 } 163 }
164 164
165 // IsTitle reports whether the rune is a title case letter. 165 // IsTitle reports whether the rune is a title case letter.
166 func IsTitle(rune int) bool { 166 func IsTitle(rune int) bool {
167 if rune < 0x80 { // quick ASCII check 167 if rune < 0x80 { // quick ASCII check
168 return false 168 return false
169 } 169 }
170 return Is(Title, rune) 170 return Is(Title, rune)
171 } 171 }
172 172
173 // IsLetter reports whether the rune is a letter.
174 func IsLetter(rune int) bool {
175 if rune < 0x80 { // quick ASCII check
176 rune &^= 'a' - 'A'
177 return 'A' <= rune && rune <= 'Z'
178 }
179 return Is(Letter, rune)
180 }
181
182 // IsSpace reports whether the rune is a white space character.
183 func IsSpace(rune int) bool {
184 if rune <= 0xFF { // quick Latin-1 check
185 switch rune {
186 case '\t', '\n', '\v', '\f', '\r', ' ', 0x85, 0xA0:
187 return true
188 }
189 return false
190 }
191 return Is(White_Space, rune)
192 }
193
194 // to maps the rune using the specified case mapping. 173 // to maps the rune using the specified case mapping.
195 func to(_case int, rune int, caseRange []CaseRange) int { 174 func to(_case int, rune int, caseRange []CaseRange) int {
196 if _case < 0 || MaxCase <= _case { 175 if _case < 0 || MaxCase <= _case {
197 return ReplacementChar // as reasonable an error as any 176 return ReplacementChar // as reasonable an error as any
198 } 177 }
199 // binary search over ranges 178 // binary search over ranges
200 lo := 0 179 lo := 0
201 hi := len(caseRange) 180 hi := len(caseRange)
202 for lo < hi { 181 for lo < hi {
203 m := lo + (hi-lo)/2 182 m := lo + (hi-lo)/2
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 } 264 }
286 265
287 // ToLower maps the rune to lower case giving priority to the special mapping. 266 // ToLower maps the rune to lower case giving priority to the special mapping.
288 func (special SpecialCase) ToLower(rune int) int { 267 func (special SpecialCase) ToLower(rune int) int {
289 r := to(LowerCase, rune, []CaseRange(special)) 268 r := to(LowerCase, rune, []CaseRange(special))
290 if r == rune { 269 if r == rune {
291 r = ToLower(rune) 270 r = ToLower(rune)
292 } 271 }
293 return r 272 return r
294 } 273 }
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b