github.com/icodeface/tls@v0.0.0-20230910023335-34df9250cd12/internal/x/text/unicode/norm/input.go (about)

     1  // Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT.
     2  
     3  // Copyright 2011 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  package norm
     8  
     9  import "unicode/utf8"
    10  
    11  type input struct {
    12  	str   string
    13  	bytes []byte
    14  }
    15  
    16  func inputBytes(str []byte) input {
    17  	return input{bytes: str}
    18  }
    19  
    20  func inputString(str string) input {
    21  	return input{str: str}
    22  }
    23  
    24  func (in *input) setBytes(str []byte) {
    25  	in.str = ""
    26  	in.bytes = str
    27  }
    28  
    29  func (in *input) setString(str string) {
    30  	in.str = str
    31  	in.bytes = nil
    32  }
    33  
    34  func (in *input) _byte(p int) byte {
    35  	if in.bytes == nil {
    36  		return in.str[p]
    37  	}
    38  	return in.bytes[p]
    39  }
    40  
    41  func (in *input) skipASCII(p, max int) int {
    42  	if in.bytes == nil {
    43  		for ; p < max && in.str[p] < utf8.RuneSelf; p++ {
    44  		}
    45  	} else {
    46  		for ; p < max && in.bytes[p] < utf8.RuneSelf; p++ {
    47  		}
    48  	}
    49  	return p
    50  }
    51  
    52  func (in *input) skipContinuationBytes(p int) int {
    53  	if in.bytes == nil {
    54  		for ; p < len(in.str) && !utf8.RuneStart(in.str[p]); p++ {
    55  		}
    56  	} else {
    57  		for ; p < len(in.bytes) && !utf8.RuneStart(in.bytes[p]); p++ {
    58  		}
    59  	}
    60  	return p
    61  }
    62  
    63  func (in *input) appendSlice(buf []byte, b, e int) []byte {
    64  	if in.bytes != nil {
    65  		return append(buf, in.bytes[b:e]...)
    66  	}
    67  	for i := b; i < e; i++ {
    68  		buf = append(buf, in.str[i])
    69  	}
    70  	return buf
    71  }
    72  
    73  func (in *input) copySlice(buf []byte, b, e int) int {
    74  	if in.bytes == nil {
    75  		return copy(buf, in.str[b:e])
    76  	}
    77  	return copy(buf, in.bytes[b:e])
    78  }
    79  
    80  func (in *input) charinfoNFC(p int) (uint16, int) {
    81  	if in.bytes == nil {
    82  		return nfcData.lookupString(in.str[p:])
    83  	}
    84  	return nfcData.lookup(in.bytes[p:])
    85  }
    86  
    87  func (in *input) charinfoNFKC(p int) (uint16, int) {
    88  	if in.bytes == nil {
    89  		return nfkcData.lookupString(in.str[p:])
    90  	}
    91  	return nfkcData.lookup(in.bytes[p:])
    92  }
    93  
    94  func (in *input) hangul(p int) (r rune) {
    95  	var size int
    96  	if in.bytes == nil {
    97  		if !isHangulString(in.str[p:]) {
    98  			return 0
    99  		}
   100  		r, size = utf8.DecodeRuneInString(in.str[p:])
   101  	} else {
   102  		if !isHangul(in.bytes[p:]) {
   103  			return 0
   104  		}
   105  		r, size = utf8.DecodeRune(in.bytes[p:])
   106  	}
   107  	if size != hangulUTF8Size {
   108  		return 0
   109  	}
   110  	return r
   111  }