// NewLenChars returns a new random string of the provided length, consisting
// of the provided byte slice of allowed characters (maximum 256).
335658
func NewLenChars(length int, chars []byte) string {
	if length == 0 {
		return ""
	}
	clen := len(chars)
	if clen < 2 || clen > 256 {
		panic("uniuri: wrong charset length for NewLenChars")
	}
	maxrb := 255 - (256 % clen)
	b := make([]byte, length)
	r := make([]byte, length+(length/4)) // storage for random bytes.
	i := 0
	for {
		if _, err := rand.Read(r); err != nil {
			panic("uniuri: error reading random bytes: " + err.Error())
		}
		for _, rb := range r {
			c := int(rb)
			if c > maxrb {
				// Skip this number to avoid modulo bias.
				continue
			}
			b[i] = chars[c%clen]
			i++
			if i == length {
				return string(b)
			}
		}
	}
}
542461
func NewLexer(r io.Reader) *Lexer {
	var b []byte
	if r != nil {
		if buffer, ok := r.(interface {
			Bytes() []byte
		}); ok {
			b = buffer.Bytes()
		} else {
			var err error
			b, err = ioutil.ReadAll(r)
			if err != nil {
				return &Lexer{
					buf: []byte{0},
					err: err,
				}
			}
		}
	}
	return NewLexerBytes(b)
}
1080752
func NewEncoder(w io.Writer) *Encoder {
	return &Encoder{w: w, escapeHTML: true}
}
301027
func RandomString(length int) string {
	var dat = make([]byte, length)
	rand.Read(dat)
	return base64.StdEncoding.EncodeToString(dat)
}
1051101
func (c *Charmap) NewEncoder() *encoding.Encoder {
	c.Init()
	return &encoding.Encoder{
		Transformer: &cmapEncoder{
			bytes:   c.bytes,
			replace: c.ReplacementChar,
		},
	}
}
364214
func RandomString(prefix string, length int) string {
	return RandomRunes(prefix, length, AlphaRunes, NumericRunes)
}
1240952
func NewHString(s string) (hstring HString, err error) {
	u16 := syscall.StringToUTF16Ptr(s)
	len := uint32(utf8.RuneCountInString(s))
	hr, _, _ := procWindowsCreateString.Call(
		uintptr(unsafe.Pointer(u16)),
		uintptr(len),
		uintptr(unsafe.Pointer(&hstring)))
	if hr != 0 {
		err = NewError(hr)
	}
	return
}
821625
func NewWriter(w io.Writer) *Writer {
	return &Writer{
		w:   w,
		enc: make([]byte, MaxEncodedLen(maxUncompressedChunkLen)),
	}
}
437940
func NewEncoder(w io.Writer) *Encoder {
	return &Encoder{
		w:          w,
		headersBuf: bytes.NewBuffer(nil),
	}
}
1342155
func RandomString(byteLength int) string {
	b := make([]byte, byteLength)
	_, err := io.ReadFull(RandReader, b)
	if err != nil {
		panic(fmt.Sprintf("Error reading random bytes: %s", err))
	}
	return base64.RawURLEncoding.EncodeToString(b)
}
712694
func RandomString(n int) string {
	p := make([]byte, n/2+1)
	crand.Read(p)
	return hex.EncodeToString(p)[:n]
}
405170
func NewHString(s string) (hstring HString, err error) {
	return HString(uintptr(0)), NewError(E_NOTIMPL)
}
433725
func newRandomReader(r *rand.Rand) *randomReader {
	return &randomReader{b: &bytes.Buffer{}, r: r}
}
49612
func NewLexer(r io.Reader) *Lexer {
	return &Lexer{
		r: buffer.NewLexer(r),
	}
}
1032313
func NewDecoder(name string) Decoder {
	cs := GetCharset(name)
	if cs == nil {
		return nil
	}
	return cs.NewDecoder()
}
1174291
func NewJSONPointerFromString(pointer string) (*JSONPointer, error) {
	if len(pointer) != 0 && pointer[0] != '/' {
		return nil, JSONPointerSyntaxError{pointer}
	}
	bytes := []byte(pointer)
	if at := badEscapeSequence.FindIndex(bytes); at != nil {
		sequence := string(bytes[at[0]:at[1]])
		return nil, BadEscapeSequence{pointer, sequence}
	}
	tokens := strings.Split(pointer, "/")[1:] // remove the leading ""
	for index, token := range tokens {
		tokens[index] = strings.Replace(
			strings.Replace(token, "~1", "/", -1),
			"~0",
			"~",
			-1)
	}
	p := JSONPointer{pointer, tokens}
	return &p, nil
}
438503
func ReplaceChars(src []string, replacer *strings.Replacer) []string {
	ret := make([]string, len(src))
	for i, s := range src {
		ret[i] = replacer.Replace(s)
	}
	return ret
}