/**
 * Revert non ascii chracters escaped by git or windows (as octal sequences \000) back to bytes.
 */
7491
func DecodePathBytes(path []byte) []byte {
	var expression = regexp.MustCompile(`\\[0-9]{3}`)
	var buffer bytes.Buffer

	// strip quotes if any
	if len(path) > 2 && path[0] == '"' && path[len(path)-1] == '"' {
		path = path[1 : len(path)-1]
	}

	base := 0
	for _, submatches := range expression.FindAllSubmatchIndex(path, -1) {
		buffer.Write(path[base:submatches[0]])

		match := string(path[submatches[0]+1 : submatches[0]+4])

		k, err := strconv.ParseUint(match, 8, 64)
		if err != nil {
			return path
		} // abort on error

		buffer.Write([]byte{byte(k)})
		base = submatches[1]
	}

	buffer.Write(path[base:len(path)])

	return buffer.Bytes()
}
204242
func UnescapeString(in string) string {
	if strings.IndexByte(in, '\\') == -1 {
		return in
	}
	return unescaper.Replace(in)
}
847784
func toSemVer(version string) string {
	// Remove the first non-digit and non-dot character as well as the ones
	// following it.
	// E.g., "1.8.19p1" -> "1.8.19".
	if i := strings.IndexFunc(version, func(c rune) bool {
		if (c < '0' || c > '9') && c != '.' {
			return true
		}
		return false
	}); i != -1 {
		version = version[:i]
	}

	// Remove the trailing dots if there's any, and then returns an empty
	// string if nothing left.
	version = strings.TrimRight(version, ".")
	if version == "" {
		return ""
	}

	numDots := strings.Count(version, ".")
	switch {
	case numDots < semVerDotsCount:
		// Add minor version and patch version.
		// E.g. "1.18" -> "1.18.0" and "481" -> "481.0.0".
		version += strings.Repeat(".0", semVerDotsCount-numDots)
	case numDots > semVerDotsCount:
		// Remove anything beyond the patch version
		// E.g. "2.0.10.4" -> "2.0.10".
		for numDots != semVerDotsCount {
			if i := strings.LastIndex(version, "."); i != -1 {
				version = version[:i]
				numDots--
			}
		}
	}

	// Remove leading zeros in major/minor/patch version.
	// E.g., "2.02"     -> "2.2"
	//       "8.0.0095" -> "8.0.95"
	var subs []string
	for _, s := range strings.Split(version, ".") {
		s := strings.TrimLeft(s, "0")
		if s == "" {
			s = "0"
		}
		subs = append(subs, s)
	}
	return strings.Join(subs, ".")
}
87138
func ReverseBytes(x uint) uint {
	if UintSize == 32 {
		return uint(ReverseBytes32(uint32(x)))
	}
	return uint(ReverseBytes64(uint64(x)))
}
131223
func (p *SortKeys) AsStringSliceComparator() StringSliceComparator {
	numeric := utils.NewIndex(p.Numeric)
	reverseIndex := utils.NewIndex(p.Reversed)
	comparators := make([]StringComparator, len(p.Keys))
	for i, k := range p.Keys {
		if numeric.Contains(k) {
			comparators[i] = LessNumericStrings
		} else {
			comparators[i] = LessStrings
		}
		if reverseIndex.Contains(k) {
			f := comparators[i]
			comparators[i] = func(l, r string) bool {
				return !f(l, r)
			}
		}
	}
	return AsStringSliceComparator(comparators)
}
549960
func ReverseUint64(v uint64) (x uint64) {
	x |= uint64(ReverseLUT[byte(v>>0)]) << 56
	x |= uint64(ReverseLUT[byte(v>>8)]) << 48
	x |= uint64(ReverseLUT[byte(v>>16)]) << 40
	x |= uint64(ReverseLUT[byte(v>>24)]) << 32
	x |= uint64(ReverseLUT[byte(v>>32)]) << 24
	x |= uint64(ReverseLUT[byte(v>>40)]) << 16
	x |= uint64(ReverseLUT[byte(v>>48)]) << 8
	x |= uint64(ReverseLUT[byte(v>>56)]) << 0
	return x
}
1332818
func decodeRefs(input string) (*git.Ref, *git.Ref) {
	refs := strings.Split(strings.TrimSpace(input), " ")
	for len(refs) < 4 {
		refs = append(refs, "")
	}

	leftRef := git.ParseRef(refs[0], refs[1])
	rightRef := git.ParseRef(refs[2], refs[3])
	return leftRef, rightRef
}
1210828
func reverseBits(i int) int {
	i = ((i << 2) & 0xc) | ((i >> 2) & 0x3)
	i = ((i << 1) & 0xa) | ((i >> 1) & 0x5)
	return i
}
1242963
func ReverseString(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}
605263
func (q *QRCode) ToSmallString(inverseColor bool) string {
	bits := q.Bitmap()
	var buf bytes.Buffer
	// if there is an odd number of rows, the last one needs special treatment
	for y := 0; y < len(bits)-1; y += 2 {
		for x := range bits[y] {
			if bits[y][x] == bits[y+1][x] {
				if bits[y][x] != inverseColor {
					buf.WriteString(" ")
				} else {
					buf.WriteString("█")
				}
			} else {
				if bits[y][x] != inverseColor {
					buf.WriteString("▄")
				} else {
					buf.WriteString("▀")
				}
			}
		}
		buf.WriteString("\n")
	}
	// special treatment for the last row if odd
	if len(bits)%2 == 1 {
		y := len(bits) - 1
		for x := range bits[y] {
			if bits[y][x] != inverseColor {
				buf.WriteString(" ")
			} else {
				buf.WriteString("▀")
			}
		}
		buf.WriteString("\n")
	}
	return buf.String()
}
1333685
func replaceNonAlpha(s string, replace byte) string {
	byts := []byte(s)
	newByts := make([]byte, len(byts))

	for i := 0; i < len(byts); i++ {
		if byts[i] < 'A' || (byts[i] > 'Z' && byts[i] < 'a') || byts[i] > 'z' {
			newByts[i] = replace
		} else {
			newByts[i] = byts[i]
		}
	}

	return string(newByts)
}
993123
func Reverse32(value uint32) (uint32) {
    value = ((value >> 1) & 0x55555555) | ((value & 0x55555555) << 1)
    value = ((value >> 2) & 0x33333333) | ((value & 0x33333333) << 2)
    value = ((value >> 4) & 0x0F0F0F0F) | ((value & 0x0F0F0F0F) << 4)
    value = ((value >> 8) & 0x00FF00FF) | ((value & 0x00FF00FF) << 8)
    value = ( value >> 16             ) | ( value               << 16)

    return value
}
1109314
func reverse(u []byte) []byte {
	// Special-case 16 bit UUIDS for speed.
	l := len(u)
	if l == 2 {
		return []byte{u[1], u[0]}
	}
	b := make([]byte, l)
	for i := 0; i < l/2+1; i++ {
		b[i], b[l-i-1] = u[l-i-1], u[i]
	}
	return b
}
1116503
func (cu *CharacterUtils) ToLowerCase(buffer []rune) {
	for i, v := range buffer {
		buffer[i] = unicode.ToLower(v)
	}
}
915788
func sanitize(b []byte) []byte {
	// Replace ` with `+"`"+`
	b = bytes.Replace(b, []byte("`"), []byte("`+\"`\"+`"), -1)

	// Replace BOM with `+"\xEF\xBB\xBF"+`
	// (A BOM is valid UTF-8 but not permitted in Go source files.
	// I wouldn't bother handling this, but for some insane reason
	// jquery.js has a BOM somewhere in the middle.)
	return bytes.Replace(b, []byte("\xEF\xBB\xBF"), []byte("`+\"\\xEF\\xBB\\xBF\"+`"), -1)
}
604864
func Reverse64(value uint64) (uint64) {
    high :=  Reverse32(uint32(value))
    low :=  Reverse32(uint32(value >> 32))

    return (uint64(high) << 32) | uint64(low)
}
18374
func (p *parser) scanCharEscape() (rune, error) {

	ch := p.moveRightGetChar()

	if ch >= '0' && ch <= '7' {
		p.moveLeft()
		return p.scanOctal(), nil
	}

	switch ch {
	case 'x':
		// support for \x{HEX} syntax from Perl and PCRE
		if p.charsRight() > 0 && p.rightChar(0) == '{' {
			p.moveRight(1)
			return p.scanHexUntilBrace()
		}
		return p.scanHex(2)
	case 'u':
		return p.scanHex(4)
	case 'a':
		return '\u0007', nil
	case 'b':
		return '\b', nil
	case 'e':
		return '\u001B', nil
	case 'f':
		return '\f', nil
	case 'n':
		return '\n', nil
	case 'r':
		return '\r', nil
	case 't':
		return '\t', nil
	case 'v':
		return '\u000B', nil
	case 'c':
		return p.scanControl()
	default:
		if !p.useOptionE() && IsWordChar(ch) {
			return 0, p.getErr(ErrUnrecognizedEscape, string(ch))
		}
		return ch, nil
	}
}