<commit_before>package json

import "github.com/gopherjs/gopherjs/js"

func parseTag(tag *js.Object) (*js.Object, *js.Object) {
	strLen := tag.Length()
	var val *js.Object
	for i := 0; i < strLen; i++ {
		start := i
		for i < strLen && tag.Call("charCodeAt", i).Int() == ' ' {
			i++
		}
		var char int
		for ; i < strLen; i++ {
			char = tag.Call("charCodeAt", i).Int()
			if char <= ' ' || char == ':' || char == '"' {
				break
			}
		}
		if i+1 >= strLen || char != ':' || tag.Call("charCodeAt", i+1).Int() {
			break
		}
		name := tag.Call("substring", start, i)
		i += 2
		start = i
		for ; i < strLen; i++ {
			char = tag.Call("charCodeAt", i).Int()
			if char == '\\' {
				i++
			} else if char == '"' {
				break
			}
		}
		if name.String() == "json" {
			val = tag.Call("substring", start, i)
			break
		}
	}
	if val == nil {
		return nil, nil
	}
	split := val.Call("indexOf", ",").Int()
	if split < 0 {
		return val, nil
	}
	return val.Call("substr", 0, split), val.Call("substr", split+1)
}

func tagContains(str *js.Object, option string) bool {
	if str == nil || str.Length() == 0 || str.Length() < len(option) {
		return false
	}
	if str.Length() == len(option) {
		return str.String() == option
	}
	return str.Call("substr", 0, len(option)+1) == option+"," || str.Call("substr", -1-len(option)) == ","+option || str.Call("includes", ","+option+",")
}<commit_msg>restructured tag code to better match stdlib json<commit_after>package json

import "github.com/gopherjs/gopherjs/js"

func getJSONTag(tag *js.Object) string {
	strLen := tag.Length()
	var val *js.Object
	for i := 0; i < strLen; i++ {
		start := i
		for i < strLen && tag.Call("charCodeAt", i).Int() == ' ' {
			i++
		}
		var char int
		for ; i < strLen; i++ {
			char = tag.Call("charCodeAt", i).Int()
			if char <= ' ' || char == ':' || char == '"' {
				break
			}
		}
		if i+1 >= strLen || char != ':' || tag.Call("charCodeAt", i+1).Int() {
			break
		}
		name := tag.Call("substring", start, i)
		i += 2
		start = i
		for ; i < strLen; i++ {
			char = tag.Call("charCodeAt", i).Int()
			if char == '\\' {
				i++
			} else if char == '"' {
				break
			}
		}
		if name.String() == "json" {
			val = tag.Call("substring", start, i)
			break
		}
	}
	if val == nil {
		return ""
	}
	return val.String()
}

type tagOptions struct {
	*js.Object
}

func parseTag(tag string) (string, tagOptions) {
	split := js.Global.Get("String").Get("indexOf").Invoke(tag, ",").Int()
	if split < 0 {
		return val, tagOptions{nil}
	}
	return js.Global.Get("String").Get("substr").Invoke(tag, 0, split), tagOptions{js.Global.Get("String").Get("substr").Invoke(tag, split+1)}
}

func (o tagOptions) Contains(option string) bool {
	if o.Object == nil || o.Length() == 0 || o.Length() < len(option) {
		return false
	}
	if str.Length() == len(option) {
		return o.String() == option
	}
	return o.Call("substr", 0, len(option)+1) == option+"," || o.Call("substr", -1-len(option)) == ","+option || o.Call("includes", ","+option+",")
}
{'fraction_non_alphanumeric': 0.22166499498495487, 'fraction_numerical': 0.007355399531929121, 'mean_word_length': 3.076294277929155, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 5, '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': '4956847', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1141, 'n_words': 279}