func Underscore(s string) string {
	if s == "" {
		return ""
	}
	u := strings.TrimSpace(s)

	u = underscoreRe.ReplaceAllString(u, "${1}_$2")
	u = dashSpaceRe.ReplaceAllString(u, "_")
	u = strings.ToLower(u)
	if IsUpper(s[0:1]) {
		return "_" + u
	}
	return u
}
func Underscore(s string) string {
	if s == "" {
		return ""
	}
	u := strings.TrimSpace(s)

	u = underscoreRe.ReplaceAllString(u, "${1}_$2")
	u = dashSpaceRe.ReplaceAllString(u, "_")
	u = strings.ToLower(u)
	if IsUpper(s[0:1]) {
		return "_" + u
	}
	return u
}
func Underscore ( s string ) string { if s == " " { return " " } u := strings . TrimSpace ( s ) u = underscoreRe . ReplaceAllString ( u , " " ) u = dashSpaceRe . ReplaceAllString ( u , " " ) u = strings . ToLower ( u ) if IsUpper ( s [ 0 : 1 ] ) { return " " + u } return u }
// TODO This is not working yet. Go's regexp package does not have some
// of the niceities in JavaScript
//
// Truncate truncates the string, accounting for word placement and chars count
// adding a morestr (defaults to ellipsis)
// func Truncate(s, morestr string, n int) string {
// 	L := len(s)
// 	if L <= n {
// 		return s
// 	}
//
// 	if morestr == "" {
// 		morestr = "..."
// 	}
//
// 	tmpl := func(c string) string {
// 		if strings.ToUpper(c) != strings.ToLower(c) {
// 			return "A"
// 		}
// 		return " "
// 	}
// 	template := s[0 : n+1]
// 	var truncateRe = regexp.MustCompile(`.(?=\W*\w*$)`)
// 	truncateRe.ReplaceAllStringFunc(template, tmpl) // 'Hello, world' -> 'HellAA AAAAA'
// 	var wwRe = regexp.MustCompile(`\w\w`)
// 	var whitespaceRe2 = regexp.MustCompile(`\s*\S+$`)
// 	if wwRe.MatchString(template[len(template)-2:]) {
// 		template = whitespaceRe2.ReplaceAllString(template, "")
// 	} else {
// 		template = strings.TrimRight(template, " \t\n")
// 	}
//
// 	if len(template+morestr) > L {
// 		return s
// 	}
// 	return s[0:len(template)] + morestr
// }
//
//     truncate: function(length, pruneStr) { //from underscore.string, author: github.com/rwz
//       var str = this.s;
//
//       length = ~~length;
//       pruneStr = pruneStr || '...';
//
//       if (str.length <= length) return new this.constructor(str);
//
//       var tmpl = function(c){ return c.toUpperCase() !== c.toLowerCase() ? 'A' : ' '; },
//         template = str.slice(0, length+1).replace(/.(?=\W*\w*$)/g, tmpl); // 'Hello, world' -> 'HellAA AAAAA'
//
//       if (template.slice(template.length-2).match(/\w\w/))
//         template = template.replace(/\s*\S+$/, '');
//       else
//         template = new S(template.slice(0, template.length-1)).trimRight().s;
//
//       return (template+pruneStr).length > str.length ? new S(str) : new S(str.slice(0, template.length)+pruneStr);
//     },
// Underscore returns converted camel cased string into a string delimited by underscores.
TODO This is not working yet . Go s regexp package does not have some of the niceities in JavaScript Truncate truncates the string accounting for word placement and chars count adding a morestr ( defaults to ellipsis ) func Truncate ( s morestr string n int ) string { L : = len ( s ) if L < = n { return s } if morestr == { morestr = ... } tmpl : = func ( c string ) string { if strings . ToUpper ( c ) ! = strings . ToLower ( c ) { return A } return } template : = s [ 0 : n + 1 ] var truncateRe = regexp . MustCompile ( . ( ? = \ W * \ w * $ ) ) truncateRe . ReplaceAllStringFunc ( template tmpl ) // Hello world - > HellAA AAAAA var wwRe = regexp . MustCompile ( \ w \ w ) var whitespaceRe2 = regexp . MustCompile ( \ s * \ S + $ ) if wwRe . MatchString ( template [ len ( template ) - 2 : ] ) { template = whitespaceRe2 . ReplaceAllString ( template ) } else { template = strings . TrimRight ( template \ t \ n ) } if len ( template + morestr ) > L { return s } return s [ 0 : len ( template ) ] + morestr } truncate : function ( length pruneStr ) { // from underscore . string author : github . com / rwz var str = this . s ; length = ~~length ; pruneStr = pruneStr || ... ; if ( str . length < = length ) return new this . constructor ( str ) ; var tmpl = function ( c ) { return c . toUpperCase () ! == c . toLowerCase () ? A : ; } template = str . slice ( 0 length + 1 ) . replace ( / . ( ? = \ W * \ w * $ ) / g tmpl ) ; // Hello world - > HellAA AAAAA if ( template . slice ( template . length - 2 ) . match ( / \ w \ w / )) template = template . replace ( / \ s * \ S + $ / ) ; else template = new S ( template . slice ( 0 template . length - 1 )) . trimRight () . s ; return ( template + pruneStr ) . length > str . length ? new S ( str ) : new S ( str . slice ( 0 template . length ) + pruneStr ) ; } Underscore returns converted camel cased string into a string delimited by underscores .