Exemple #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
}
Exemple #2
0
func (typ dateFormatType) Compile(args []string) (fmt.MessageInput, error) {
	l := len(args)
	var res string

	if l == 0 || (l == 1 && args[0] == OptionDefault) {
		res = TimeFormatRoot + ":" + string(typ) + ":" + OptionDefault
	} else if l == 1 && (args[0] == OptionShort || args[0] == OptionLong) {
		res = TimeFormatRoot + ":" + string(typ) + ":" + args[0]
	}

	if res != "" {
		return dateFormat(res), nil
	}

	return nil, fmt.NewError(fmt.MalformedFormatSpecificationErrorResourceKey, args)
}
Exemple #3
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
}
Exemple #4
0
func parse(args []string) (fmt.MessageInput, error) {
	if len(args) == 1 {
		return pluralStem(args[0]), nil
	}
	return nil, fmt.NewError(fmt.MalformedFormatSpecificationErrorResourceKey, args)
}