Beispiel #1
0
func parse(args []string) (fmt.MessageInput, error) {
	if len(args) != 0 {
		return nil, fmt.NewError(fmt.MalformedFormatSpecificationErrorResourceKey, args)
	}

	return fmt.SimpleMessageInput("%#v"), nil
}
Beispiel #2
0
func parse(args []string) (fmt.MessageInput, error) {
	b := new(bytes.Buffer)
	var length string
	var sign, pad bool

	for _, str := range args {
		lengthVal, err := strconv.Atoi(str)
		switch {
		case str == PadZero:
			pad = true
		case str == Sign:
			sign = true
		case err == nil && lengthVal > 0:
			length = str
		default:
			return nil, fmt.NewError(fmt.MalformedFormatSpecificationErrorResourceKey, Format, str)
		}
	}

	b.WriteRune('%')

	if sign {
		b.WriteRune('+')
	}

	if pad {
		b.WriteRune('0')
	}

	if length != "" {
		b.WriteString(length)
	}

	b.WriteRune('d')

	return fmt.SimpleMessageInput(b.String()), nil
}