Beispiel #1
0
func camelCase(src string) string {
	byteSrc := []byte(src)
	chunks := camelingRegex.FindAll(byteSrc, -1)
	for idx, val := range chunks {
		if idx > 0 {
			chunks[idx] = bytes.Title(val)
		}
	}

	return string(bytes.Title(bytes.Join(chunks, nil)))
}
Beispiel #2
0
func normalizeKeyToField(k []byte) string {
	k = bytes.ToLower(k)
	k = bytes.Title(k)
	k = bytes.Replace(k, []byte(" "), []byte(""), -1)
	k = bytes.TrimSpace(k)
	return string(k)
}
Beispiel #3
0
func main() {
	quickBrownFox := []byte("The quick brown fox jumped over the lazy dog")

	title := bytes.Title(quickBrownFox)
	log.Printf("Title turned %q into %q", quickBrownFox, title)

	allTitle := bytes.ToTitle(quickBrownFox)
	log.Printf("ToTitle turned %q to %q", quickBrownFox, allTitle)

	allTitleTurkish := bytes.ToTitleSpecial(unicode.TurkishCase, quickBrownFox)
	log.Printf("ToTitleSpecial turned %q into %q using the Turkish case rules", quickBrownFox, allTitleTurkish)

	lower := bytes.ToLower(title)
	log.Printf("ToLower turned %q into %q", title, lower)

	turkishCapitalI := []byte("İ")
	turkishLowerI := bytes.ToLowerSpecial(unicode.TurkishCase, turkishCapitalI)
	log.Printf("ToLowerSpecial turned %q into %q using the Turkish case rules", turkishCapitalI, turkishLowerI)

	upper := bytes.ToUpper(quickBrownFox)
	log.Printf("ToUpper turned %q to %q", quickBrownFox, upper)

	upperSpecial := bytes.ToUpperSpecial(unicode.TurkishCase, quickBrownFox)
	log.Printf("ToUpperSpecial turned %q into %q using the Turkish case rules", quickBrownFox, upperSpecial)
}
Beispiel #4
0
func snakeToCamel(src string) string {
	byteSrc := []byte(src)
	chunks := camelRegex.FindAll(byteSrc, -1)
	for i, val := range chunks {
		chunks[i] = bytes.Title(val)
	}
	return string(bytes.Join(chunks, nil))
}
Beispiel #5
0
func pascalCase(src string, sep string) string {
	byteSrc := []byte(src)
	chunks := camelingRegex.FindAll(byteSrc, -1)
	for idx, val := range chunks {
		chunks[idx] = bytes.Title(val)
	}
	return string(bytes.Join(chunks, []byte(sep)))
}
Beispiel #6
0
// ToCamelCase convert string to CamelCase, the first char also in upper case.
func ToCamelCase(s string) string {
	chunks := alphaNumRegex.FindAll([]byte(s), -1)
	for i, val := range chunks {
		chunks[i] = bytes.Title(val)
	}

	return string(bytes.Join(chunks, nil))
}
Beispiel #7
0
func titleCase(src string) string {
	byteSrc := []byte(src)
	chunks := titlingRegex.FindAll(byteSrc, -1)
	for idx, val := range chunks {
		chunks[idx] = bytes.Title(val)
	}
	return string(bytes.Join(chunks, nil))
}
Beispiel #8
0
func GetExportedName(src string) string {
	byteSrc := []byte(src)
	chunks := exportedNameRegex.FindAll(byteSrc, -1)
	for idx, val := range chunks {
		chunks[idx] = bytes.Title(val)
	}
	return string(bytes.Join(chunks, nil))
}
Beispiel #9
0
func (p *Parser) parseCommandBlockStart(cmd, opts []byte) error {
	if p.task.Commands == nil {
		p.task.Commands = make(map[string]*CommandBlock)
	}

	pieces := bytes.Split(opts, []byte(" "))
	name := ""
	settingsStartIndex := 0

	if !bytes.Contains(pieces[0], []byte("=")) {
		name = string(pieces[0])
		settingsStartIndex = 1
	}

	_, set := p.task.Commands[name]
	if set {
		return fmt.Errorf("%s block with name '%s' already exists. Line %d", cmd, opts, p.currentLine)
	}

	p.task.Commands[name] = &CommandBlock{
		Name: name,
	}

	if len(pieces) > 0 {
		for _, setting := range pieces[settingsStartIndex:] {
			parts := bytes.SplitN(setting, []byte("="), 2)
			if len(parts) < 2 {
				continue
			}

			taskReflect := reflect.ValueOf(p.task.Commands[name])
			// struct
			s := taskReflect.Elem()
			// exported field
			f := s.FieldByName(string(bytes.Title(parts[0])))
			if f.IsValid() {
				// A Value can be changed only if it is
				// addressable and was not obtained by
				// the use of unexported struct fields.
				if f.CanSet() {
					// change value of N
					if f.Kind() == reflect.String {
						if f.String() != "" {
							return fmt.Errorf("Cannot redeclare setting '%s'. Line %d", parts[0], p.currentLine)
						}
						f.SetString(string(parts[1]))
					}
				}
			} else {
				return fmt.Errorf("Invalid block setting \"%s\". Line %d", parts[0], p.currentLine)
			}
		}
	}
	p.task.currentBlock = name
	p.runningMode = modeCommand
	return nil
}
Beispiel #10
0
func camelCase(src string) string {
	camelingRegex := regexp.MustCompile("[0-9A-Za-z]+")
	byteSrc := []byte(src)
	chunks := camelingRegex.FindAll(byteSrc, -1)
	for idx, val := range chunks {
		chunks[idx] = bytes.Title(val)
	}
	return string(bytes.Join(chunks, nil))
}
func UpperCamelCase(src string) string {
	byteSrc := []byte(src)
	chunks := camelingRegex.FindAll(byteSrc, -1)
	for idx, val := range chunks {
		if idx > 0 {
			chunks[idx] = bytes.Title(val)
		}
	}
	camel := string(bytes.Join(chunks, nil))
	return strings.ToUpper(string(camel[0])) + camel[1:]
}
Beispiel #12
0
func (v *vimDoc) buildHelpTag(text []byte) []byte {
	if v.flags&flagPascal == 0 {
		text = bytes.ToLower(text)
		text = bytes.Replace(text, []byte{' '}, []byte{'_'}, -1)
	} else {
		text = bytes.Title(text)
		text = bytes.Replace(text, []byte{' '}, []byte{}, -1)
	}

	return []byte(fmt.Sprintf("%s-%s", v.title, text))
}
Beispiel #13
0
func camelCase(src string, export bool) string {
	re := regexp.MustCompile("[0-9A-Za-z]+")
	byteSrc := []byte(src)
	chunks := re.FindAll(byteSrc, -1)
	for idx, val := range chunks {
		if idx > 0 || export {
			chunks[idx] = bytes.Title(val)
		}
	}
	return string(bytes.Join(chunks, nil))
}
Beispiel #14
0
func camelKey(src string) string {
	// From: https://github.com/etgryphon/stringUp

	var camelingRegex = regexp.MustCompile("[0-9A-Za-z]+")

	byteSrc := []byte(src)
	chunks := camelingRegex.FindAll(byteSrc, -1)
	for idx, val := range chunks {
		chunks[idx] = bytes.Title(val)
	}
	return string(bytes.Join(chunks, nil))
}
Beispiel #15
0
// camelCase transform string to CamelCase
func camelCase(s string) string {
	b := []byte(s)
	matched := reg.FindAll(b, -1)
	for i, m := range matched {
		if i == 0 {
			continue
		}
		matched[i] = bytes.Title(m)
	}

	return string(bytes.Join(matched, nil))
}
Beispiel #16
0
func CanonicalHeaderKey(key []byte) []byte {
	return bytes.Title(key)
}
Beispiel #17
0
func (v *view) onVcommand(c viewCommand) {
	lastClass := v.lastCommand.Cmd.class()
	if c.Cmd.class() != lastClass || lastClass == vCommandClassMisc {
		v.buf.FinalizeActionGroup()
	}

	count := c.Count
	if count == 0 {
		count = 1
	}

	for i := 0; i < count; i++ {
		switch c.Cmd {
		case vCommandMoveCursorForward:
			v.moveCursorForward()

		case vCommandMoveCursorBackward:
			v.moveCursorBackward()

		case vCommandMoveCursorWordForward:
			v.moveCursorWordFoward()

		case vCommandMoveCursorWordEnd:
			v.moveCursorWordEnd()

		case vCommandMoveCursorWordBackward:
			v.moveCursorWordBackward()

		case vCommandMoveCursorNextLine:
			v.moveCursorNextLine()

		case vCommandMoveCursorPrevLine:
			v.moveCursorPrevLine()

		case vCommandMoveCursorBeginningOfLine:
			v.moveCursorBeginningOfLine()

		case vCommandMoveCursorEndOfLine:
			v.moveCursorEndOfLine()

		case vCommandMoveCursorBeginningOfFile:
			v.moveCursorBeginningOfFile()

		case vCommandMoveCursorEndOfFile:
			v.moveCursorEndOfFile()
			/*
				case vCommandMoveCursorToLine:
					v.MoveCursorToLine(int(arg))
			*/

		case vCommandMoveViewHalfForward:
			v.maybeMoveViewNlines(v.height() / 2)
		case vCommandMoveViewHalfBackward:
			v.moveViewNlines(-v.height() / 2)
		case vCommandInsertRune:
			v.buf.InsertRune(v.cursor, c.Rune)
		case vCommandYank:
			v.yank()
		case vCommandDeleteRuneBackward:
			v.buf.DeleteRuneBackward(v.cursor)
		case vCommandDeleteRune:
			v.buf.DeleteRune(v.cursor)
		case vCommandKillLine:
			v.killLine()
		case vCommandKillWord:
			v.killWord()
		case vCommandKillWordBackward:
			v.killWordBackward()
		case vCommandUndo:
			v.buf.Undo()
		case vCommandRedo:
			v.buf.Redo()
		case vCommandWordToUpper:
			v.wordTo(bytes.ToUpper)
		case vCommandWordToTitle:
			v.wordTo(func(s []byte) []byte {
				return bytes.Title(bytes.ToLower(s))
			})
		case vCommandWordToLower:
			v.wordTo(bytes.ToLower)
		}
	}

	v.lastCommand = c
}
Beispiel #18
0
func ExampleTitle() {
	fmt.Printf("%s", bytes.Title([]byte("her royal highness")))
	// Output: Her Royal Highness
}
Beispiel #19
0
func main() {
	s := []byte("hello, world!")
	fmt.Println(string(bytes.Title(s)))
	fmt.Println(string(s))
}
Beispiel #20
0
func (v *view) on_vcommand(cmd vcommand, arg rune) {
	last_class := v.last_vcommand.class()
	if cmd.class() != last_class || last_class == vcommand_class_misc {
		v.finalize_action_group()
	}

	switch cmd {
	case vcommand_move_cursor_forward:
		v.move_cursor_forward()
	case vcommand_move_cursor_backward:
		v.move_cursor_backward()
	case vcommand_move_cursor_word_forward:
		v.move_cursor_word_forward()
	case vcommand_move_cursor_word_backward:
		v.move_cursor_word_backward()
	case vcommand_move_cursor_next_line:
		v.move_cursor_next_line()
	case vcommand_move_cursor_prev_line:
		v.move_cursor_prev_line()
	case vcommand_move_cursor_beginning_of_line:
		v.move_cursor_beginning_of_line()
	case vcommand_move_cursor_end_of_line:
		v.move_cursor_end_of_line()
	case vcommand_move_cursor_beginning_of_file:
		v.move_cursor_beginning_of_file()
	case vcommand_move_cursor_end_of_file:
		v.move_cursor_end_of_file()
	case vcommand_move_cursor_to_line:
		v.move_cursor_to_line(int(arg))
	case vcommand_move_view_half_forward:
		v.maybe_move_view_n_lines(v.height() / 2)
	case vcommand_move_view_half_backward:
		v.move_view_n_lines(-v.height() / 2)
	case vcommand_set_mark:
		v.set_mark()
	case vcommand_swap_cursor_and_mark:
		v.swap_cursor_and_mark()
	case vcommand_insert_rune:
		v.insert_rune(arg)
	case vcommand_yank:
		v.yank()
	case vcommand_delete_rune_backward:
		v.delete_rune_backward()
	case vcommand_delete_rune:
		v.delete_rune()
	case vcommand_kill_line:
		v.kill_line()
	case vcommand_kill_word:
		v.kill_word()
	case vcommand_kill_word_backward:
		v.kill_word_backward()
	case vcommand_kill_region:
		v.kill_region()
	case vcommand_copy_region:
		v.copy_region()
	case vcommand_undo:
		v.undo()
	case vcommand_redo:
		v.redo()
	case vcommand_autocompl_init:
		v.init_autocompl()
	case vcommand_autocompl_finalize:
		v.ac.finalize(v)
		v.ac = nil
	case vcommand_autocompl_move_cursor_up:
		v.ac.move_cursor_up()
	case vcommand_autocompl_move_cursor_down:
		v.ac.move_cursor_down()
	case vcommand_indent_region:
		v.indent_region()
	case vcommand_deindent_region:
		v.deindent_region()
	case vcommand_region_to_upper:
		v.region_to(bytes.ToUpper)
	case vcommand_region_to_lower:
		v.region_to(bytes.ToLower)
	case vcommand_word_to_upper:
		v.word_to(bytes.ToUpper)
	case vcommand_word_to_title:
		v.word_to(func(s []byte) []byte {
			return bytes.Title(bytes.ToLower(s))
		})
	case vcommand_word_to_lower:
		v.word_to(bytes.ToLower)
	}

	v.last_vcommand = cmd
}