<commit_before>package main

// TODO(CaptainHayashi): Petition for move to baps3-go

// Feature is the type for known feature flags.
type Feature uint8

const (
	// FtUnknown represents an unknown feature.
	FtUnknown Feature = iota
	// FtFileLoad represents the FileLoad standard feature.
	FtFileLoad
	// FtPlayStop represents the PlayStop standard feature.
	FtPlayStop
	// FtSeek represents the Seek standard feature.
	FtSeek
	// FtEnd represents the End standard feature.
	FtEnd
	// FtTimeReport represents the TimeReport standard feature.
	FtTimeReport
	// FtPlaylist represents the Playlist standard feature.
	FtPlaylist
	// FtPlaylistAutoAdvance represents the Playlist.AutoAdvance feature.
	FtPlaylistAutoAdvance
	// FtPlaylistTextItems represents the Playlist.TextItems feature.
	FtPlaylistTextItems
)<commit_msg>Add stringification boilerplate for features.<commit_after>package main

// TODO(CaptainHayashi): Petition for move to baps3-go

// Feature is the type for known feature flags.
type Feature int

const (
	/* Feature constants.
	 *
	 * When adding to this, also add the string equivalent to ftStrings.
	 */

	// FtUnknown represents an unknown feature.
	FtUnknown Feature = iota
	// FtFileLoad represents the FileLoad standard feature.
	FtFileLoad
	// FtPlayStop represents the PlayStop standard feature.
	FtPlayStop
	// FtSeek represents the Seek standard feature.
	FtSeek
	// FtEnd represents the End standard feature.
	FtEnd
	// FtTimeReport represents the TimeReport standard feature.
	FtTimeReport
	// FtPlaylist represents the Playlist standard feature.
	FtPlaylist
	// FtPlaylistAutoAdvance represents the Playlist.AutoAdvance feature.
	FtPlaylistAutoAdvance
	// FtPlaylistTextItems represents the Playlist.TextItems feature.
	FtPlaylistTextItems
)

// Yes, a global variable.
// Go can't handle constant arrays.
var ftStrings = []string{
	"<UNKNOWN FEATURE>",    // FtUnknown
	"FileLoad",             // FtFileLoad
	"PlayStop",             // FtPlayStop
	"Seek",                 // FtSeek
	"End",                  // FtEnd
	"TimeReport",           // FtTimeReport
	"Playlist",             // FtPlaylist
	"Playlist.AutoAdvance", // FtPlaylistAutoAdvance
	"Playlist.TextItems",   // FtPlaylistTextItems
}

// IsUnknown returns whether word represents a feature unknown to Bifrost.
func (word Feature) IsUnknown() bool {
	return word == FtUnknown
}

func (word Feature) String() string {
	return ftStrings[int(word)]
}

// LookupFeature finds the equivalent Feature for a string.
// If the message word is not known to Bifrost, it will return FtUnknown.
func LookupFeature(word string) Feature {
	// This is O(n) on the size of ftStrings, which is unfortunate, but
	// probably ok.
	for i, str := range ftStrings {
		if str == word {
			return Feature(i)
		}
	}

	return FtUnknown
}
{'fraction_non_alphanumeric': 0.07557932263814617, 'fraction_numerical': 0.0010695187165775401, 'mean_word_length': 3.4752791068580544, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '592816', 'n_tokens_mistral': 856, 'n_tokens_neox': 836, 'n_words': 288}