package net
import (
)
type file struct {
file *os.File
data []byte
atEOF bool
}
func ( *file) () { .file.Close() }
func ( *file) () ( string, bool) {
:= .data
:= 0
for = 0; < len(); ++ {
if [] == '\n' {
= string([0:])
= true
++
:= len() -
copy([0:], [:])
.data = [0:]
return
}
}
if .atEOF && len(.data) > 0 {
= string()
.data = .data[0:0]
= true
}
return
}
func ( *file) () ( string, bool) {
if , = .getLineFromData(); {
return
}
if len(.data) < cap(.data) {
:= len(.data)
, := io.ReadFull(.file, .data[:cap(.data)])
if >= 0 {
.data = .data[0 : +]
}
if == io.EOF || == io.ErrUnexpectedEOF {
.atEOF = true
}
}
, = .getLineFromData()
return
}
func ( string) (*file, error) {
, := os.Open()
if != nil {
return nil,
}
return &file{, make([]byte, 0, 64*1024), false}, nil
}
func ( string) ( time.Time, int64, error) {
, := os.Stat()
if != nil {
return time.Time{}, 0,
}
return .ModTime(), .Size(), nil
}
func ( string, string) int {
:= 0
for := 0; < len(); ++ {
if bytealg.IndexByteString(, []) >= 0 {
++
}
}
return
}
func ( string, string) []string {
:= make([]string, 1+countAnyByte(, ))
:= 0
:= 0
for := 0; < len(); ++ {
if bytealg.IndexByteString(, []) >= 0 {
if < {
[] = [:]
++
}
= + 1
}
}
if < len() {
[] = [:]
++
}
return [0:]
}
func ( string) []string { return splitAtBytes(, " \r\t\n") }
const big = 0xFFFFFF
func ( string) ( int, int, bool) {
= 0
for = 0; < len() && '0' <= [] && [] <= '9'; ++ {
= *10 + int([]-'0')
if >= big {
return big, , false
}
}
if == 0 {
return 0, 0, false
}
return , , true
}
func ( string) ( int, int, bool) {
= 0
for = 0; < len(); ++ {
if '0' <= [] && [] <= '9' {
*= 16
+= int([] - '0')
} else if 'a' <= [] && [] <= 'f' {
*= 16
+= int([]-'a') + 10
} else if 'A' <= [] && [] <= 'F' {
*= 16
+= int([]-'A') + 10
} else {
break
}
if >= big {
return 0, , false
}
}
if == 0 {
return 0, , false
}
return , , true
}
func ( string, byte) (byte, bool) {
if len() > 2 && [2] != {
return 0, false
}
, , := xtoi([:2])
return byte(), && == 2
}
func ( int) string {
if < 0 {
return "-" + uitoa(uint(-))
}
return uitoa(uint())
}
func ( uint) string {
if == 0 {
return "0"
}
var [20]byte
:= len() - 1
for >= 10 {
:= / 10
[] = byte('0' + - *10)
--
=
}
[] = byte('0' + )
return string([:])
}
func ( []byte, uint32) []byte {
if == 0 {
return append(, '0')
}
for := 7; >= 0; -- {
:= >> uint(*4)
if > 0 {
= append(, hexDigit[&0xf])
}
}
return
}
func ( string, byte) int {
:= 0
for := 0; < len(); ++ {
if [] == {
++
}
}
return
}
func ( string, byte) int {
:= len()
for --; >= 0; -- {
if [] == {
break
}
}
return
}
func ( []byte) {
for , := range {
if 'A' <= && <= 'Z' {
[] += 'a' - 'A'
}
}
}
func ( byte) byte {
if 'A' <= && <= 'Z' {
return + ('a' - 'A')
}
return
}
func ( []byte) []byte {
for len() > 0 && isSpace([0]) {
= [1:]
}
for len() > 0 && isSpace([len()-1]) {
= [:len()-1]
}
return
}
func ( byte) bool {
return == ' ' || == '\t' || == '\n' || == '\r'
}
func ( []byte) []byte {
if := bytealg.IndexByte(, '#'); != -1 {
return [:]
}
return
}
func ( []byte, func( []byte) error) error {
for len() > 0 {
:= bytealg.IndexByte(, '\n')
if == -1 {
return ()
}
:= [:+1]
= [+1:]
if := (); != nil {
return
}
}
return nil
}
func ( []byte, func( []byte) error) error {
= trimSpace()
for len() > 0 {
:= bytealg.IndexByte(, ' ')
if == -1 {
return ()
}
if := trimSpace([:]); len() > 0 {
if := (); != nil {
return
}
}
= trimSpace([+1:])
}
return nil
}
func (, string) bool {
return len() >= len() && [len()-len():] ==
}
func (, string) bool {
return len() >= len() && stringsEqualFold([len()-len():], )
}
func (, string) bool {
return len() >= len() && [:len()] ==
}
func (, string) bool {
if len() != len() {
return false
}
for := 0; < len(); ++ {
if lowerASCII([]) != lowerASCII([]) {
return false
}
}
return true
}
func ( io.Reader) ( []byte, error) {
:= make([]byte, 1024)
for {
, := .Read()
= append(, [:]...)
if == io.EOF {
return , nil
}
if != nil {
return nil,
}
}
}
func ( string) string {
:= os.Getenv("GODEBUG")
for := 0; < len()-len()-1; ++ {
if > 0 && [-1] != ',' {
continue
}
:= [+len():]
if [0] != '=' || [:+len()] != {
continue
}
:= [1:]
for , := range {
if == ',' {
return [:]
}
}
return
}
return ""
}