<commit_before>// Copyright (c) 2014 <NAME>. All rights reserved.
//
// Use of this source code is governed by the BSD license that can be found in
// the LICENSE file.

package protocol

// CheckFunc checks if a given r at index i is within its specification.
type CheckFunc func(i int, r rune) (valid bool)

// Or returns a CheckFunc that returns true if any of the given funcs return
// true.
// If no funcs are given, it always returns true.
// It will short circuit on the first true func.
func Or(funcs ...CheckFunc) CheckFunc {
	return func(i int, r rune) bool {
		for _, f := range funcs {
			if f(i, r) {
				return true
			}
		}

		return false
	}
}

// And returns a CheckFunc that returns true if all of the given funcs return
// true.
// If no funcs are given, it always returns true.
// It will short circuit on the first false func.
func And(funcs ...CheckFunc) CheckFunc {
	return func(i int, r rune) bool {
		for _, f := range funcs {
			if !f(i, r) {
				return false
			}
		}

		return true
	}
}

// Letter checks if r is a valid letter, as according to RFC 2812.
func Letter(i int, r rune) bool {
	return (r >= 'A' && r <= 'Z') || (r >= 'a' && r <= 'z') // A-Z / a-z
}

// Special checks if r is a valid special character, as according to RFC 2812.
func Special(i int, r rune) bool {
	return (r >= ']' && r <= '`') || (r >= '{' && r <= '}') // "[", "]", "\", "`", "_", "^", "{", "|", "}"
}

// Digit checks if r is a valid digit, as according to RFC 2812.
func Digit(i int, r rune) bool {
	return r >= '0' && r <= '9' // 0-9
}

// Nickname checks if r at index i is a valid nickname character, as according
// to RFC 2812.
func Nickname(i int, r rune) bool {
	if i >= 9 {
		// Nicknames have a maximum length of 9 characters. The runes are
		// 0-indexed.
		return false
	}
	if i == 0 {
		if !Letter(i, r) && !Special(i, r) {
			return false
		}

		return true
	}

	if !Letter(i, r) && !Digit(i, r) && !Special(i, r) && r != '-' {
		return false
	}
<commit_msg>Change maximum nickname length<commit_after>// Copyright (c) 2014 <NAME>. All rights reserved.
//
// Use of this source code is governed by the BSD license that can be found in
// the LICENSE file.

package protocol

// CheckFunc checks if a given r at index i is within its specification.
type CheckFunc func(i int, r rune) (valid bool)

// Or returns a CheckFunc that returns true if any of the given funcs return
// true.
// If no funcs are given, it always returns true.
// It will short circuit on the first true func.
func Or(funcs ...CheckFunc) CheckFunc {
	return func(i int, r rune) bool {
		for _, f := range funcs {
			if f(i, r) {
				return true
			}
		}

		return false
	}
}

// And returns a CheckFunc that returns true if all of the given funcs return
// true.
// If no funcs are given, it always returns true.
// It will short circuit on the first false func.
func And(funcs ...CheckFunc) CheckFunc {
	return func(i int, r rune) bool {
		for _, f := range funcs {
			if !f(i, r) {
				return false
			}
		}

		return true
	}
}

// Letter checks if r is a valid letter, as according to RFC 2812.
func Letter(i int, r rune) bool {
	return (r >= 'A' && r <= 'Z') || (r >= 'a' && r <= 'z') // A-Z / a-z
}

// Special checks if r is a valid special character, as according to RFC 2812.
func Special(i int, r rune) bool {
	return (r >= ']' && r <= '`') || (r >= '{' && r <= '}') // "[", "]", "\", "`", "_", "^", "{", "|", "}"
}

// Digit checks if r is a valid digit, as according to RFC 2812.
func Digit(i int, r rune) bool {
	return r >= '0' && r <= '9' // 0-9
}

// MaxMaximumNickLen specifies the maximum length that a nickname may be.
const MaximumNickLen = 15

// Nickname checks if r at index i is a valid nickname character, as according
// to RFC 2812.
func Nickname(i int, r rune) bool {
	if i >= MaximumNickLen {
		// Nicknames have a maximum length of 9 characters. The runes are
		// 0-indexed.
		return false
	}
	if i == 0 {
		if !Letter(i, r) && !Special(i, r) {
			return false
		}

		return true
	}

	if !Letter(i, r) && !Digit(i, r) && !Special(i, r) && r != '-' {
		return false
	}

{'fraction_non_alphanumeric': 0.14463718543855364, 'fraction_numerical': 0.013926215489860738, 'mean_word_length': 2.678346810422282, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1828091', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1393, 'n_words': 616}