π FileMgr
π
/
opt
/
golang
/
1.22.0
/
src
/
unicode
/
utf8
βοΈ /
β¬ Kembali
// Copyright 2013 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package utf8_test import ( "fmt" "unicode/utf8" ) func ExampleDecodeLastRune() { b := []byte("Hello, δΈη") for len(b) > 0 { r, size := utf8.DecodeLastRune(b) fmt.Printf("%c %v\n", r, size) b = b[:len(b)-size] } // Output: // η 3 // δΈ 3 // 1 // , 1 // o 1 // l 1 // l 1 // e 1 // H 1 } func ExampleDecodeLastRuneInString() { str := "Hello, δΈη" for len(str) > 0 { r, size := utf8.DecodeLastRuneInString(str) fmt.Printf("%c %v\n", r, size) str = str[:len(str)-size] } // Output: // η 3 // δΈ 3 // 1 // , 1 // o 1 // l 1 // l 1 // e 1 // H 1 } func ExampleDecodeRune() { b := []byte("Hello, δΈη") for len(b) > 0 { r, size := utf8.DecodeRune(b) fmt.Printf("%c %v\n", r, size) b = b[size:] } // Output: // H 1 // e 1 // l 1 // l 1 // o 1 // , 1 // 1 // δΈ 3 // η 3 } func ExampleDecodeRuneInString() { str := "Hello, δΈη" for len(str) > 0 { r, size := utf8.DecodeRuneInString(str) fmt.Printf("%c %v\n", r, size) str = str[size:] } // Output: // H 1 // e 1 // l 1 // l 1 // o 1 // , 1 // 1 // δΈ 3 // η 3 } func ExampleEncodeRune() { r := 'δΈ' buf := make([]byte, 3) n := utf8.EncodeRune(buf, r) fmt.Println(buf) fmt.Println(n) // Output: // [228 184 150] // 3 } func ExampleEncodeRune_outOfRange() { runes := []rune{ // Less than 0, out of range. -1, // Greater than 0x10FFFF, out of range. 0x110000, // The Unicode replacement character. utf8.RuneError, } for i, c := range runes { buf := make([]byte, 3) size := utf8.EncodeRune(buf, c) fmt.Printf("%d: %d %[2]s %d\n", i, buf, size) } // Output: // 0: [239 191 189] οΏ½ 3 // 1: [239 191 189] οΏ½ 3 // 2: [239 191 189] οΏ½ 3 } func ExampleFullRune() { buf := []byte{228, 184, 150} // δΈ fmt.Println(utf8.FullRune(buf)) fmt.Println(utf8.FullRune(buf[:2])) // Output: // true // false } func ExampleFullRuneInString() { str := "δΈ" fmt.Println(utf8.FullRuneInString(str)) fmt.Println(utf8.FullRuneInString(str[:2])) // Output: // true // false } func ExampleRuneCount() { buf := []byte("Hello, δΈη") fmt.Println("bytes =", len(buf)) fmt.Println("runes =", utf8.RuneCount(buf)) // Output: // bytes = 13 // runes = 9 } func ExampleRuneCountInString() { str := "Hello, δΈη" fmt.Println("bytes =", len(str)) fmt.Println("runes =", utf8.RuneCountInString(str)) // Output: // bytes = 13 // runes = 9 } func ExampleRuneLen() { fmt.Println(utf8.RuneLen('a')) fmt.Println(utf8.RuneLen('η')) // Output: // 1 // 3 } func ExampleRuneStart() { buf := []byte("aη") fmt.Println(utf8.RuneStart(buf[0])) fmt.Println(utf8.RuneStart(buf[1])) fmt.Println(utf8.RuneStart(buf[2])) // Output: // true // true // false } func ExampleValid() { valid := []byte("Hello, δΈη") invalid := []byte{0xff, 0xfe, 0xfd} fmt.Println(utf8.Valid(valid)) fmt.Println(utf8.Valid(invalid)) // Output: // true // false } func ExampleValidRune() { valid := 'a' invalid := rune(0xfffffff) fmt.Println(utf8.ValidRune(valid)) fmt.Println(utf8.ValidRune(invalid)) // Output: // true // false } func ExampleValidString() { valid := "Hello, δΈη" invalid := string([]byte{0xff, 0xfe, 0xfd}) fmt.Println(utf8.ValidString(valid)) fmt.Println(utf8.ValidString(invalid)) // Output: // true // false } func ExampleAppendRune() { buf1 := utf8.AppendRune(nil, 0x10000) buf2 := utf8.AppendRune([]byte("init"), 0x10000) fmt.Println(string(buf1)) fmt.Println(string(buf2)) // Output: // π // initπ }
πΎ Simpan
Batal
β¬ unicode
3 item
Nama
Tipe
Ukuran
Diubah
Aksi
π΅
example_test.go
go
3.6 KB
2024-02-02 18:09
βοΈ
ποΈ
π€
π
π΅
utf8.go
go
16.4 KB
2024-02-02 18:09
βοΈ
ποΈ
π€
π
π΅
utf8_test.go
go
16.2 KB
2024-02-02 18:09
βοΈ
ποΈ
π€
π
βοΈ Rename
Nama Baru
Simpan
Batal