0% found this document useful (0 votes)
32 views2 pages

Input Go

This document defines an input struct and associated methods for processing UTF-8 encoded text. The input struct can hold a string or byte slice and provides methods for accessing characters, skipping ranges, and retrieving Unicode properties.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

Input Go

This document defines an input struct and associated methods for processing UTF-8 encoded text. The input struct can hold a string or byte slice and provides methods for accessing characters, skipping ranges, and retrieving Unicode properties.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

// Copyright 2011 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 norm

import "unicode/utf8"

type input struct {


str string
bytes []byte
}

func inputBytes(str []byte) input {


return input{bytes: str}
}

func inputString(str string) input {


return input{str: str}
}

func (in *input) setBytes(str []byte) {


[Link] = ""
[Link] = str
}

func (in *input) setString(str string) {


[Link] = str
[Link] = nil
}

func (in *input) _byte(p int) byte {


if [Link] == nil {
return [Link][p]
}
return [Link][p]
}

func (in *input) skipASCII(p, max int) int {


if [Link] == nil {
for ; p < max && [Link][p] < [Link]; p++ {
}
} else {
for ; p < max && [Link][p] < [Link]; p++ {
}
}
return p
}

func (in *input) skipContinuationBytes(p int) int {


if [Link] == nil {
for ; p < len([Link]) && ![Link]([Link][p]); p++ {
}
} else {
for ; p < len([Link]) && ![Link]([Link][p]); p++ {
}
}
return p
}
func (in *input) appendSlice(buf []byte, b, e int) []byte {
if [Link] != nil {
return append(buf, [Link][b:e]...)
}
for i := b; i < e; i++ {
buf = append(buf, [Link][i])
}
return buf
}

func (in *input) copySlice(buf []byte, b, e int) int {


if [Link] == nil {
return copy(buf, [Link][b:e])
}
return copy(buf, [Link][b:e])
}

func (in *input) charinfoNFC(p int) (uint16, int) {


if [Link] == nil {
return [Link]([Link][p:])
}
return [Link]([Link][p:])
}

func (in *input) charinfoNFKC(p int) (uint16, int) {


if [Link] == nil {
return [Link]([Link][p:])
}
return [Link]([Link][p:])
}

func (in *input) hangul(p int) (r rune) {


var size int
if [Link] == nil {
if !isHangulString([Link][p:]) {
return 0
}
r, size = [Link]([Link][p:])
} else {
if !isHangul([Link][p:]) {
return 0
}
r, size = [Link]([Link][p:])
}
if size != hangulUTF8Size {
return 0
}
return r
}

You might also like