unicode

package
v1.21.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 9, 2023 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

unicodeパッケージは、Unicodeコードポイントのいくつかのプロパティをテストするためのデータと関数を提供します。

Example (Is)

「Is」で始まる関数は、runeがどの範囲のテーブルに属しているかを調べるために使用できます。ただし、runesは複数の範囲に当てはまる場合があることに注意してください。

package main

import (
	"github.com/shogo82148/std/fmt"
	"github.com/shogo82148/std/unicode"
)

func main() {

	// 異なる型のルーンを持つ定数
	const mixed = "\b5Ὂg̀9! ℃ᾭG"
	for _, c := range mixed {
		fmt.Printf("For %q:\n", c)
		if unicode.IsControl(c) {
			fmt.Println("\tis control rune")
		}
		if unicode.IsDigit(c) {
			fmt.Println("\tis digit rune")
		}
		if unicode.IsGraphic(c) {
			fmt.Println("\tis graphic rune")
		}
		if unicode.IsLetter(c) {
			fmt.Println("\tis letter rune")
		}
		if unicode.IsLower(c) {
			fmt.Println("\tis lower case rune")
		}
		if unicode.IsMark(c) {
			fmt.Println("\tis mark rune")
		}
		if unicode.IsNumber(c) {
			fmt.Println("\tis number rune")
		}
		if unicode.IsPrint(c) {
			fmt.Println("\tis printable rune")
		}
		if !unicode.IsPrint(c) {
			fmt.Println("\tis not printable rune")
		}
		if unicode.IsPunct(c) {
			fmt.Println("\tis punct rune")
		}
		if unicode.IsSpace(c) {
			fmt.Println("\tis space rune")
		}
		if unicode.IsSymbol(c) {
			fmt.Println("\tis symbol rune")
		}
		if unicode.IsTitle(c) {
			fmt.Println("\tis title case rune")
		}
		if unicode.IsUpper(c) {
			fmt.Println("\tis upper case rune")
		}
	}

}
Output:

For '\b':
	is control rune
	is not printable rune
For '5':
	is digit rune
	is graphic rune
	is number rune
	is printable rune
For 'Ὂ':
	is graphic rune
	is letter rune
	is printable rune
	is upper case rune
For 'g':
	is graphic rune
	is letter rune
	is lower case rune
	is printable rune
For '̀':
	is graphic rune
	is mark rune
	is printable rune
For '9':
	is digit rune
	is graphic rune
	is number rune
	is printable rune
For '!':
	is graphic rune
	is printable rune
	is punct rune
For ' ':
	is graphic rune
	is printable rune
	is space rune
For '℃':
	is graphic rune
	is printable rune
	is symbol rune
For 'ᾭ':
	is graphic rune
	is letter rune
	is printable rune
	is title case rune
For 'G':
	is graphic rune
	is letter rune
	is printable rune
	is upper case rune

Index

Examples

Constants

View Source
const (
	MaxRune         = '\U0010FFFF'
	ReplacementChar = '\uFFFD'
	MaxASCII        = '\u007F'
	MaxLatin1       = '\u00FF'
)
View Source
const (
	UpperCase = iota
	LowerCase
	TitleCase
	MaxCase
)

CaseMapping 内の CaseRanges のデルタ配列への索引。

View Source
const (
	UpperLower = MaxRune + 1
)

もしCaseRangeのDeltaフィールドがUpperLowerであれば、 これは(Upper Lower Upper Lowerのような)シーケンスを表すことを意味します。

View Source
const Version = "15.0.0"

Version はテーブルが派生されるUnicodeエディションです。

Variables

View Source
var (
	Cc     = _Cc
	Cf     = _Cf
	Co     = _Co
	Cs     = _Cs
	Digit  = _Nd
	Nd     = _Nd
	Letter = _L
	L      = _L
	Lm     = _Lm
	Lo     = _Lo
	Lower  = _Ll
	Ll     = _Ll
	Mark   = _M
	M      = _M
	Mc     = _Mc
	Me     = _Me
	Mn     = _Mn
	Nl     = _Nl
	No     = _No
	Number = _N
	N      = _N
	Other  = _C
	C      = _C
	Pc     = _Pc
	Pd     = _Pd
	Pe     = _Pe
	Pf     = _Pf
	Pi     = _Pi
	Po     = _Po
	Ps     = _Ps
	Punct  = _P
	P      = _P
	Sc     = _Sc
	Sk     = _Sk
	Sm     = _Sm
	So     = _So
	Space  = _Z
	Z      = _Z
	Symbol = _S
	S      = _S
	Title  = _Lt
	Lt     = _Lt
	Upper  = _Lu
	Lu     = _Lu
	Zl     = _Zl
	Zp     = _Zp
	Zs     = _Zs
)

これらの変数は*RangeTable型です。

View Source
var (
	Adlam                  = _Adlam
	Ahom                   = _Ahom
	Anatolian_Hieroglyphs  = _Anatolian_Hieroglyphs
	Arabic                 = _Arabic
	Armenian               = _Armenian
	Avestan                = _Avestan
	Balinese               = _Balinese
	Bamum                  = _Bamum
	Bassa_Vah              = _Bassa_Vah
	Batak                  = _Batak
	Bengali                = _Bengali
	Bhaiksuki              = _Bhaiksuki
	Bopomofo               = _Bopomofo
	Brahmi                 = _Brahmi
	Braille                = _Braille
	Buginese               = _Buginese
	Buhid                  = _Buhid
	Canadian_Aboriginal    = _Canadian_Aboriginal
	Carian                 = _Carian
	Caucasian_Albanian     = _Caucasian_Albanian
	Chakma                 = _Chakma
	Cham                   = _Cham
	Cherokee               = _Cherokee
	Chorasmian             = _Chorasmian
	Common                 = _Common
	Coptic                 = _Coptic
	Cuneiform              = _Cuneiform
	Cypriot                = _Cypriot
	Cypro_Minoan           = _Cypro_Minoan
	Cyrillic               = _Cyrillic
	Deseret                = _Deseret
	Devanagari             = _Devanagari
	Dives_Akuru            = _Dives_Akuru
	Dogra                  = _Dogra
	Duployan               = _Duployan
	Egyptian_Hieroglyphs   = _Egyptian_Hieroglyphs
	Elbasan                = _Elbasan
	Elymaic                = _Elymaic
	Ethiopic               = _Ethiopic
	Georgian               = _Georgian
	Glagolitic             = _Glagolitic
	Gothic                 = _Gothic
	Grantha                = _Grantha
	Greek                  = _Greek
	Gujarati               = _Gujarati
	Gunjala_Gondi          = _Gunjala_Gondi
	Gurmukhi               = _Gurmukhi
	Han                    = _Han
	Hangul                 = _Hangul
	Hanifi_Rohingya        = _Hanifi_Rohingya
	Hanunoo                = _Hanunoo
	Hatran                 = _Hatran
	Hebrew                 = _Hebrew
	Hiragana               = _Hiragana
	Imperial_Aramaic       = _Imperial_Aramaic
	Inherited              = _Inherited
	Inscriptional_Pahlavi  = _Inscriptional_Pahlavi
	Inscriptional_Parthian = _Inscriptional_Parthian
	Javanese               = _Javanese
	Kaithi                 = _Kaithi
	Kannada                = _Kannada
	Katakana               = _Katakana
	Kawi                   = _Kawi
	Kayah_Li               = _Kayah_Li
	Kharoshthi             = _Kharoshthi
	Khitan_Small_Script    = _Khitan_Small_Script
	Khmer                  = _Khmer
	Khojki                 = _Khojki
	Khudawadi              = _Khudawadi
	Lao                    = _Lao
	Latin                  = _Latin
	Lepcha                 = _Lepcha
	Limbu                  = _Limbu
	Linear_A               = _Linear_A
	Linear_B               = _Linear_B
	Lisu                   = _Lisu
	Lycian                 = _Lycian
	Lydian                 = _Lydian
	Mahajani               = _Mahajani
	Makasar                = _Makasar
	Malayalam              = _Malayalam
	Mandaic                = _Mandaic
	Manichaean             = _Manichaean
	Marchen                = _Marchen
	Masaram_Gondi          = _Masaram_Gondi
	Medefaidrin            = _Medefaidrin
	Meetei_Mayek           = _Meetei_Mayek
	Mende_Kikakui          = _Mende_Kikakui
	Meroitic_Cursive       = _Meroitic_Cursive
	Meroitic_Hieroglyphs   = _Meroitic_Hieroglyphs
	Miao                   = _Miao
	Modi                   = _Modi
	Mongolian              = _Mongolian
	Mro                    = _Mro
	Multani                = _Multani
	Myanmar                = _Myanmar
	Nabataean              = _Nabataean
	Nag_Mundari            = _Nag_Mundari
	Nandinagari            = _Nandinagari
	New_Tai_Lue            = _New_Tai_Lue
	Newa                   = _Newa
	Nko                    = _Nko
	Nushu                  = _Nushu
	Nyiakeng_Puachue_Hmong = _Nyiakeng_Puachue_Hmong
	Ogham                  = _Ogham
	Ol_Chiki               = _Ol_Chiki
	Old_Hungarian          = _Old_Hungarian
	Old_Italic             = _Old_Italic
	Old_North_Arabian      = _Old_North_Arabian
	Old_Permic             = _Old_Permic
	Old_Persian            = _Old_Persian
	Old_Sogdian            = _Old_Sogdian
	Old_South_Arabian      = _Old_South_Arabian
	Old_Turkic             = _Old_Turkic
	Old_Uyghur             = _Old_Uyghur
	Oriya                  = _Oriya
	Osage                  = _Osage
	Osmanya                = _Osmanya
	Pahawh_Hmong           = _Pahawh_Hmong
	Palmyrene              = _Palmyrene
	Pau_Cin_Hau            = _Pau_Cin_Hau
	Phags_Pa               = _Phags_Pa
	Phoenician             = _Phoenician
	Psalter_Pahlavi        = _Psalter_Pahlavi
	Rejang                 = _Rejang
	Runic                  = _Runic
	Samaritan              = _Samaritan
	Saurashtra             = _Saurashtra
	Sharada                = _Sharada
	Shavian                = _Shavian
	Siddham                = _Siddham
	SignWriting            = _SignWriting
	Sinhala                = _Sinhala
	Sogdian                = _Sogdian
	Sora_Sompeng           = _Sora_Sompeng
	Soyombo                = _Soyombo
	Sundanese              = _Sundanese
	Syloti_Nagri           = _Syloti_Nagri
	Syriac                 = _Syriac
	Tagalog                = _Tagalog
	Tagbanwa               = _Tagbanwa
	Tai_Le                 = _Tai_Le
	Tai_Tham               = _Tai_Tham
	Tai_Viet               = _Tai_Viet
	Takri                  = _Takri
	Tamil                  = _Tamil
	Tangsa                 = _Tangsa
	Tangut                 = _Tangut
	Telugu                 = _Telugu
	Thaana                 = _Thaana
	Thai                   = _Thai
	Tibetan                = _Tibetan
	Tifinagh               = _Tifinagh
	Tirhuta                = _Tirhuta
	Toto                   = _Toto
	Ugaritic               = _Ugaritic
	Vai                    = _Vai
	Vithkuqi               = _Vithkuqi
	Wancho                 = _Wancho
	Warang_Citi            = _Warang_Citi
	Yezidi                 = _Yezidi
	Yi                     = _Yi
	Zanabazar_Square       = _Zanabazar_Square
)

これらの変数は*RangeTable型です。

View Source
var (
	ASCII_Hex_Digit                    = _ASCII_Hex_Digit
	Bidi_Control                       = _Bidi_Control
	Dash                               = _Dash
	Deprecated                         = _Deprecated
	Diacritic                          = _Diacritic
	Extender                           = _Extender
	Hex_Digit                          = _Hex_Digit
	Hyphen                             = _Hyphen
	IDS_Binary_Operator                = _IDS_Binary_Operator
	IDS_Trinary_Operator               = _IDS_Trinary_Operator
	Ideographic                        = _Ideographic
	Join_Control                       = _Join_Control
	Logical_Order_Exception            = _Logical_Order_Exception
	Noncharacter_Code_Point            = _Noncharacter_Code_Point
	Other_Alphabetic                   = _Other_Alphabetic
	Other_Default_Ignorable_Code_Point = _Other_Default_Ignorable_Code_Point
	Other_Grapheme_Extend              = _Other_Grapheme_Extend
	Other_ID_Continue                  = _Other_ID_Continue
	Other_ID_Start                     = _Other_ID_Start
	Other_Lowercase                    = _Other_Lowercase
	Other_Math                         = _Other_Math
	Other_Uppercase                    = _Other_Uppercase
	Pattern_Syntax                     = _Pattern_Syntax
	Pattern_White_Space                = _Pattern_White_Space
	Prepended_Concatenation_Mark       = _Prepended_Concatenation_Mark
	Quotation_Mark                     = _Quotation_Mark
	Radical                            = _Radical
	Regional_Indicator                 = _Regional_Indicator
	STerm                              = _Sentence_Terminal
	Sentence_Terminal                  = _Sentence_Terminal
	Soft_Dotted                        = _Soft_Dotted
	Terminal_Punctuation               = _Terminal_Punctuation
	Unified_Ideograph                  = _Unified_Ideograph
	Variation_Selector                 = _Variation_Selector
	White_Space                        = _White_Space
)

これらの変数は*RangeTable型を持っています。

View Source
var CaseRanges = _CaseRanges

CaseRangesは、非自己マッピングを持つすべての文字の大文字小文字変換に関するテーブルです。

View Source
var Categories = map[string]*RangeTable{
	"C":  C,
	"Cc": Cc,
	"Cf": Cf,
	"Co": Co,
	"Cs": Cs,
	"L":  L,
	"Ll": Ll,
	"Lm": Lm,
	"Lo": Lo,
	"Lt": Lt,
	"Lu": Lu,
	"M":  M,
	"Mc": Mc,
	"Me": Me,
	"Mn": Mn,
	"N":  N,
	"Nd": Nd,
	"Nl": Nl,
	"No": No,
	"P":  P,
	"Pc": Pc,
	"Pd": Pd,
	"Pe": Pe,
	"Pf": Pf,
	"Pi": Pi,
	"Po": Po,
	"Ps": Ps,
	"S":  S,
	"Sc": Sc,
	"Sk": Sk,
	"Sm": Sm,
	"So": So,
	"Z":  Z,
	"Zl": Zl,
	"Zp": Zp,
	"Zs": Zs,
}

CategoriesはUnicodeのカテゴリーテーブルの集合です。

View Source
var FoldCategory = map[string]*RangeTable{
	"L":  foldL,
	"Ll": foldLl,
	"Lt": foldLt,
	"Lu": foldLu,
	"M":  foldM,
	"Mn": foldMn,
}

FoldCategoryはカテゴリ名を、カテゴリ内のコードポイントと単純な大文字小文字変換で等価なカテゴリ外のコードポイントのテーブルにマッピングします。 カテゴリ名のエントリが存在しない場合、そのようなポイントは存在しません。

View Source
var FoldScript = map[string]*RangeTable{
	"Common":    foldCommon,
	"Greek":     foldGreek,
	"Inherited": foldInherited,
}

FoldScriptはスクリプト名をスクリプト内のコードポイントに対して単純なケースフォールディングで等価なスクリプト外のコードポイントのテーブルにマッピングします。 スクリプト名のエントリが存在しない場合、そのようなポイントは存在しません。

View Source
var GraphicRanges = []*RangeTable{
	L, M, N, P, S, Zs,
}

GraphicRangesはUnicodeに基づいてグラフィック文字のセットを定義します。

View Source
var PrintRanges = []*RangeTable{
	L, M, N, P, S,
}

PrintRangesはGoによる印刷可能な文字のセットを定義します。 ASCIIスペース、U+0020は別途扱われます。

View Source
var Properties = map[string]*RangeTable{
	"ASCII_Hex_Digit":                    ASCII_Hex_Digit,
	"Bidi_Control":                       Bidi_Control,
	"Dash":                               Dash,
	"Deprecated":                         Deprecated,
	"Diacritic":                          Diacritic,
	"Extender":                           Extender,
	"Hex_Digit":                          Hex_Digit,
	"Hyphen":                             Hyphen,
	"IDS_Binary_Operator":                IDS_Binary_Operator,
	"IDS_Trinary_Operator":               IDS_Trinary_Operator,
	"Ideographic":                        Ideographic,
	"Join_Control":                       Join_Control,
	"Logical_Order_Exception":            Logical_Order_Exception,
	"Noncharacter_Code_Point":            Noncharacter_Code_Point,
	"Other_Alphabetic":                   Other_Alphabetic,
	"Other_Default_Ignorable_Code_Point": Other_Default_Ignorable_Code_Point,
	"Other_Grapheme_Extend":              Other_Grapheme_Extend,
	"Other_ID_Continue":                  Other_ID_Continue,
	"Other_ID_Start":                     Other_ID_Start,
	"Other_Lowercase":                    Other_Lowercase,
	"Other_Math":                         Other_Math,
	"Other_Uppercase":                    Other_Uppercase,
	"Pattern_Syntax":                     Pattern_Syntax,
	"Pattern_White_Space":                Pattern_White_Space,
	"Prepended_Concatenation_Mark":       Prepended_Concatenation_Mark,
	"Quotation_Mark":                     Quotation_Mark,
	"Radical":                            Radical,
	"Regional_Indicator":                 Regional_Indicator,
	"Sentence_Terminal":                  Sentence_Terminal,
	"STerm":                              Sentence_Terminal,
	"Soft_Dotted":                        Soft_Dotted,
	"Terminal_Punctuation":               Terminal_Punctuation,
	"Unified_Ideograph":                  Unified_Ideograph,
	"Variation_Selector":                 Variation_Selector,
	"White_Space":                        White_Space,
}

PropertiesはUnicodeプロパティテーブルの集合です。

View Source
var Scripts = map[string]*RangeTable{}/* 163 elements not displayed */

ScriptsはUnicodeスクリプトテーブルの集合です。

Functions

func In added in v1.2.0

func In(r rune, ranges ...*RangeTable) bool

ランジのいずれかのメンバーかどうかを報告する。

func Is

func Is(rangeTab *RangeTable, r rune) bool

指定された範囲テーブル内にルーンが含まれているかどうかを報告します。

func IsControl

func IsControl(r rune) bool

IsControlはルーンが制御文字であるかどうかを報告します。 C (その他)のUnicodeカテゴリにはサロゲートなど、より多くのコードポイントが含まれています。 それらをテストするにはIs(C, r)を使用してください。

func IsDigit

func IsDigit(r rune) bool

IsDigitはルーンが10進数の数字かどうかを報告します。

Example
package main

import (
	"github.com/shogo82148/std/fmt"
	"github.com/shogo82148/std/unicode"
)

func main() {
	fmt.Printf("%t\n", unicode.IsDigit('৩'))
	fmt.Printf("%t\n", unicode.IsDigit('A'))
}
Output:

true
false

func IsGraphic

func IsGraphic(r rune) bool

IsGraphicはUnicodeによってグラフィックとして定義されたルーンかどうかを報告します。 これには、カテゴリL、M、N、P、S、Zsの文字が含まれます。

func IsLetter

func IsLetter(r rune) bool

IsLetterはルーンが文字(カテゴリーL)であるかどうかを報告します。

Example
package main

import (
	"github.com/shogo82148/std/fmt"
	"github.com/shogo82148/std/unicode"
)

func main() {
	fmt.Printf("%t\n", unicode.IsLetter('A'))
	fmt.Printf("%t\n", unicode.IsLetter('7'))
}
Output:

true
false

func IsLower

func IsLower(r rune) bool

IsLowerは、ルーンが小文字の文字かどうかを報告します。

Example
package main

import (
	"github.com/shogo82148/std/fmt"
	"github.com/shogo82148/std/unicode"
)

func main() {
	fmt.Printf("%t\n", unicode.IsLower('a'))
	fmt.Printf("%t\n", unicode.IsLower('A'))
}
Output:

true
false

func IsMark

func IsMark(r rune) bool

IsMarkは、ルーンがマーク文字(カテゴリM)であるかどうかを報告します。

func IsNumber

func IsNumber(r rune) bool

IsNumberはルーンが数字(カテゴリーN)であるかどうかを報告します。

Example
package main

import (
	"github.com/shogo82148/std/fmt"
	"github.com/shogo82148/std/unicode"
)

func main() {
	fmt.Printf("%t\n", unicode.IsNumber('Ⅷ'))
	fmt.Printf("%t\n", unicode.IsNumber('A'))
}
Output:

true
false

func IsOneOf

func IsOneOf(ranges []*RangeTable, r rune) bool

IsOneOfは、ルーンがいずれかの範囲のメンバーであるかどうかを報告します。 関数"In"はより良いシグネチャを提供し、IsOneOfよりも使われるべきです。

func IsPrint

func IsPrint(r rune) bool

IsPrintは、Goによって印字可能として定義されているルーンかどうかを報告します。これには文字、マーク、数字、句読点、記号、およびASCIIスペース文字が含まれます。これはカテゴリL、M、N、P、S、およびASCIIスペース文字と同じ分類です(ただし、唯一のスペース文字はASCIIスペース、U+0020です)。IsGraphicとは異なり、この区分にはASCIIスペース文字のみが含まれています。

func IsPunct

func IsPunct(r rune) bool

IsPunctはruneがUnicodeの句読点(カテゴリP)であるかどうかを報告します。

func IsSpace

func IsSpace(r rune) bool

IsSpaceは、UnicodeのWhite Spaceプロパティによって定義された空白文字であるかどうかを報告します。 これには、Latin-1スペースに次の文字が含まれます。

'\t'、'\n'、'\v'、'\f'、'\r'、' '、U+0085(NEL)、U+00A0(NBSP)。

スペーシング文字の他の定義は、カテゴリZおよびプロパティPattern_White_Spaceによって設定されています。

Example
package main

import (
	"github.com/shogo82148/std/fmt"
	"github.com/shogo82148/std/unicode"
)

func main() {
	fmt.Printf("%t\n", unicode.IsSpace(' '))
	fmt.Printf("%t\n", unicode.IsSpace('\n'))
	fmt.Printf("%t\n", unicode.IsSpace('\t'))
	fmt.Printf("%t\n", unicode.IsSpace('a'))
}
Output:

true
true
true
false

func IsSymbol

func IsSymbol(r rune) bool

IsSymbolはルーンが記号の文字であるかどうかを報告します。

func IsTitle

func IsTitle(r rune) bool

IsTitleは、与えられたルーンがタイトルケースの文字であるかどうかを報告します。

Example
package main

import (
	"github.com/shogo82148/std/fmt"
	"github.com/shogo82148/std/unicode"
)

func main() {
	fmt.Printf("%t\n", unicode.IsTitle('Dž'))
	fmt.Printf("%t\n", unicode.IsTitle('a'))
}
Output:

true
false

func IsUpper

func IsUpper(r rune) bool

IsUpperはルーンが大文字のアルファベットかどうかを報告します。

Example
package main

import (
	"github.com/shogo82148/std/fmt"
	"github.com/shogo82148/std/unicode"
)

func main() {
	fmt.Printf("%t\n", unicode.IsUpper('A'))
	fmt.Printf("%t\n", unicode.IsUpper('a'))
}
Output:

true
false

func SimpleFold

func SimpleFold(r rune) rune

SimpleFoldは、Unicodeが定義するシンプルな大文字小文字変換に基づいて、Unicodeコードポイントに相当するコードポイントを反復します。rune自体を含むruneに相当するコードポイントの中で、SimpleFoldは、存在する場合はrよりも大きい最小のruneを返し、存在しない場合は0以上の最小のruneを返します。rが有効なUnicodeコードポイントでない場合、SimpleFold(r)はrを返します。 例えば:

SimpleFold('A') = 'a' SimpleFold('a') = 'A'

SimpleFold('K') = 'k' SimpleFold('k') = '\u212A' (ケルビン記号、K) SimpleFold('\u212A') = 'K'

SimpleFold('1') = '1'

SimpleFold(-2) = -2

Example
package main

import (
	"github.com/shogo82148/std/fmt"
	"github.com/shogo82148/std/unicode"
)

func main() {
	fmt.Printf("%#U\n", unicode.SimpleFold('A'))      // 'a'
	fmt.Printf("%#U\n", unicode.SimpleFold('a'))      // 'A'
	fmt.Printf("%#U\n", unicode.SimpleFold('K'))      // 'k'
	fmt.Printf("%#U\n", unicode.SimpleFold('k'))      // '\u212A' (ケルビン記号、K)
	fmt.Printf("%#U\n", unicode.SimpleFold('\u212A')) // 'K'
	fmt.Printf("%#U\n", unicode.SimpleFold('1'))      // '1'

}
Output:

U+0061 'a'
U+0041 'A'
U+006B 'k'
U+212A 'K'
U+004B 'K'
U+0031 '1'

func To

func To(_case int, r rune) rune

指定されたケースに符文をマッピングします:大文字、小文字、またはタイトルケース。

Example
package main

import (
	"github.com/shogo82148/std/fmt"
	"github.com/shogo82148/std/unicode"
)

func main() {
	const lcG = 'g'
	fmt.Printf("%#U\n", unicode.To(unicode.UpperCase, lcG))
	fmt.Printf("%#U\n", unicode.To(unicode.LowerCase, lcG))
	fmt.Printf("%#U\n", unicode.To(unicode.TitleCase, lcG))

	const ucG = 'G'
	fmt.Printf("%#U\n", unicode.To(unicode.UpperCase, ucG))
	fmt.Printf("%#U\n", unicode.To(unicode.LowerCase, ucG))
	fmt.Printf("%#U\n", unicode.To(unicode.TitleCase, ucG))

}
Output:

U+0047 'G'
U+0067 'g'
U+0047 'G'
U+0047 'G'
U+0067 'g'
U+0047 'G'

func ToLower

func ToLower(r rune) rune

ToLowerはルーン文字を小文字にマッピングします。

Example
package main

import (
	"github.com/shogo82148/std/fmt"
	"github.com/shogo82148/std/unicode"
)

func main() {
	const ucG = 'G'
	fmt.Printf("%#U\n", unicode.ToLower(ucG))

}
Output:

U+0067 'g'

func ToTitle

func ToTitle(r rune) rune

ToTitleはルーンをタイトルケースにマッピングします。

Example
package main

import (
	"github.com/shogo82148/std/fmt"
	"github.com/shogo82148/std/unicode"
)

func main() {
	const ucG = 'g'
	fmt.Printf("%#U\n", unicode.ToTitle(ucG))

}
Output:

U+0047 'G'

func ToUpper

func ToUpper(r rune) rune

ToUpperはルーンを大文字にマッピングします。

Example
package main

import (
	"github.com/shogo82148/std/fmt"
	"github.com/shogo82148/std/unicode"
)

func main() {
	const ucG = 'g'
	fmt.Printf("%#U\n", unicode.ToUpper(ucG))

}
Output:

U+0047 'G'

Types

type CaseRange

type CaseRange struct {
	Lo    uint32
	Hi    uint32
	Delta d
}

CaseRangeは、単純な(1つのコードポイントから別のコードポイントへの)大文字小文字変換のためのUnicodeコードポイントの範囲を表します。 範囲は、LoからHiまでの範囲で、固定のストライド1で実行されます。デルタは、その文字の異なるケースに到達するためにコードポイントに追加する数値です。デルタは負数になることもあります。ゼロの場合、対応するケースに文字があることを意味します。特別な場合として、交互に対応する大文字と小文字のペアのシーケンスを表すものがあります。これは、固定デルタの

{UpperLower、UpperLower、UpperLower}

と表示されます。

定数UpperLowerには、通常ありえないデルタ値があります。

type Range16

type Range16 struct {
	Lo     uint16
	Hi     uint16
	Stride uint16
}

Range16は16ビットのUnicodeコードポイントの範囲を表します。範囲はLoからHiまでの値を含み、指定されたストライドを持ちます。

type Range32

type Range32 struct {
	Lo     uint32
	Hi     uint32
	Stride uint32
}

Range32はUnicodeコードポイントの範囲を表し、16ビットに収まらない値が1つ以上含まれる場合に使用されます。この範囲はLoからHiまでの間(Hiも含む)で、指定されたストライドを持ちます。LoとHiは常に1<<16以上である必要があります。

type RangeTable

type RangeTable struct {
	R16         []Range16
	R32         []Range32
	LatinOffset int
}

RangeTableは、セット内のUnicodeコードポイントを範囲ごとにリストアップして定義します。 範囲は2つのスライスにリストされます。16ビット範囲のスライスと32ビット範囲のスライスです。 2つのスライスはソートされた順序で且つ重複しないようにする必要があります。 また、R32には値が0x10000(1<<16)以上のもののみ含まれるべきです。

type SpecialCase

type SpecialCase []CaseRange

SpecialCaseはトルコ語などの言語固有の大文字小文字マッピングを表します。 SpecialCaseのメソッドは、標準のマッピングをカスタマイズするために(オーバーライドすることによって)使用されます。

Example
package main

import (
	"github.com/shogo82148/std/fmt"
	"github.com/shogo82148/std/unicode"
)

func main() {
	t := unicode.TurkishCase

	const lci = 'i'
	fmt.Printf("%#U\n", t.ToLower(lci))
	fmt.Printf("%#U\n", t.ToTitle(lci))
	fmt.Printf("%#U\n", t.ToUpper(lci))

	const uci = 'İ'
	fmt.Printf("%#U\n", t.ToLower(uci))
	fmt.Printf("%#U\n", t.ToTitle(uci))
	fmt.Printf("%#U\n", t.ToUpper(uci))

}
Output:

U+0069 'i'
U+0130 'İ'
U+0130 'İ'
U+0069 'i'
U+0130 'İ'
U+0130 'İ'
var AzeriCase SpecialCase = _TurkishCase
var TurkishCase SpecialCase = _TurkishCase

func (SpecialCase) ToLower

func (special SpecialCase) ToLower(r rune) rune

ToLowerはルーンを小文字にマッピングしますが、特別なマッピングに優先します。

func (SpecialCase) ToTitle

func (special SpecialCase) ToTitle(r rune) rune

ToTitleはルーンをタイトルケースにマッピングし、特別なマッピングを優先します。

func (SpecialCase) ToUpper

func (special SpecialCase) ToUpper(r rune) rune

ToUpperはルーンを大文字にマッピングしますが、特別なマッピングに優先します。

Directories

Path Synopsis
Package utf16はUTF-16シーケンスのエンコードとデコードを実装します。
Package utf16はUTF-16シーケンスのエンコードとデコードを実装します。
パッケージutf8はUTF-8でエンコードされたテキストをサポートするための関数や定数を実装しています。
パッケージutf8はUTF-8でエンコードされたテキストをサポートするための関数や定数を実装しています。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL