コード例 #1
0
ファイル: es5pather.go プロジェクト: Serulian/compiler
// InnerInstanceName returns the name of an inner instance of the given type, when accessed under a
// type instance which structurally composes it.
func (p Pather) InnerInstanceName(innerType typegraph.TypeReference) string {
	var name = unidecode.Unidecode(innerType.ReferredType().Name())
	if !innerType.HasGenerics() {
		return name
	}

	for _, generic := range innerType.Generics() {
		name = name + "$"
		name = name + p.InnerInstanceName(generic)
	}

	return name
}
コード例 #2
0
ファイル: upload.go プロジェクト: dansackett/write-better
// uploadHandler reads POST data from the file field and sets it in the app
func uploaderHandler(w http.ResponseWriter, req *http.Request) {
	// Use io.Reader type of req.FormFile to read the file and headers
	file, _, err := req.FormFile("textFile")
	if err != nil {
		io.WriteString(w, err.Error())
		return
	}

	// Receive the bytes from the file and store them in a data variable
	data, err := ioutil.ReadAll(file)
	if err != nil {
		io.WriteString(w, err.Error())
		return
	}

	appText = unidecode.Unidecode(string(data))

	w.Header().Set("Location", "/process")
	w.WriteHeader(http.StatusTemporaryRedirect)
}
コード例 #3
0
ファイル: slug.go プロジェクト: Xetius/grafana
// MakeLang returns slug generated from provided string and will use provided
// language for chars substitution.
func MakeLang(s string, lang string) (slug string) {
	slug = strings.TrimSpace(s)

	// Custom substitutions
	// Always substitute runes first
	slug = SubstituteRune(slug, CustomRuneSub)
	slug = Substitute(slug, CustomSub)

	// Process string with selected substitution language
	switch lang {
	case "de":
		slug = SubstituteRune(slug, deSub)
	case "en":
		slug = SubstituteRune(slug, enSub)
	case "pl":
		slug = SubstituteRune(slug, plSub)
	case "es":
		slug = SubstituteRune(slug, esSub)
	default: // fallback to "en" if lang not found
		slug = SubstituteRune(slug, enSub)
	}

	slug = SubstituteRune(slug, defaultSub)

	// Process all non ASCII symbols
	slug = unidecode.Unidecode(slug)

	slug = strings.ToLower(slug)

	// Process all remaining symbols
	slug = regexp.MustCompile("[^a-z0-9-_]").ReplaceAllString(slug, "-")
	slug = regexp.MustCompile("-+").ReplaceAllString(slug, "-")
	slug = strings.Trim(slug, "-")

	if MaxLength > 0 {
		slug = smartTruncate(slug)
	}

	return slug
}
コード例 #4
0
ファイル: es5pather.go プロジェクト: Serulian/compiler
// GetMemberName returns the name of the given member.
func (p Pather) GetMemberName(member typegraph.TGMember) string {
	return strings.Replace(unidecode.Unidecode(member.ChildName()), "*", "$", 1)
}
コード例 #5
0
ファイル: slug.go プロジェクト: rainycape/gondola
// Slug returns a slugified version of the given string, which
// consists in transliterating unicode characters to ascii
// (e.g. ó becomes o and â becomes a), replacing all sequences of
// whitespaces with '-' and converting to lowercase. Very useful
// for making arbitrary strings, like a post title, part of URLs.
func Slug(s string) string {
	decoded := unidecode.Unidecode(s)
	spaceless := slugRegexp.ReplaceAllString(decoded, "-")
	return strings.ToLower(strings.Trim(spaceless, "-"))
}