1. Ross Light
  2. yaml

Source

yaml / chars.go

// Copyright (c) 2011 Ross Light.

package yaml

import (
	"strings"
)

const bomRune = 0xfeff

const (
	nbJSONMin = 0x000020
	nbJSONMax = 0x10ffff
)

var lineFeedSlice = []rune{'\n'}

const (
	decimalDigits = `0123456789`
	hexDigits     = decimalDigits + `abcdefABCDEF`
	asciiLetters  = `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789`

	breakChars = "\n\r"
	whitespace = " \t"
	wordChars  = `-` + asciiLetters + decimalDigits
	tagChars   = wordChars + `%#;/?:@&=+$.~*'()_`
	uriChars   = tagChars + `!,[]`

	indicatorChars     = "-?:,[]{}#&*!|>'\"%@`"
	flowIndicatorChars = `,[]{}`
)

func isASCII(r rune) bool {
	return r&0x80 == 0
}

func isJSONChar(r rune) bool {
	return (r >= nbJSONMin && r <= nbJSONMax) || r == '\t'
}

func containsRune(s string, r rune) bool {
	return strings.IndexRune(s, r) >= 0
}

// joinRunes concatenates the elements of a to create a single array of runes.
// sep is placed between elements.
func joinRunes(a [][]rune, sep []rune) []rune {
	if len(a) == 0 {
		return []rune{}
	}
	if len(a) == 1 {
		return a[0]
	}

	size := len(sep) * (len(a) - 1)
	for i := range a {
		size += len(a[i])
	}

	buf := make([]rune, 0, size)
	for i := range a {
		if i > 0 {
			buf = append(buf, sep...)
		}
		buf = append(buf, a[i]...)
	}
	return buf
}