Ejemplo n.º 1
0
func parseForm(query string) (m map[string][]string, err os.Error) {
	data := make(map[string]*vector.StringVector)
	for _, kv := range strings.Split(query, "&", 0) {
		kvPair := strings.Split(kv, "=", 2)

		var key, value string
		var e os.Error
		key, e = URLUnescape(kvPair[0])
		if e == nil && len(kvPair) > 1 {
			value, e = URLUnescape(kvPair[1])
		}
		if e != nil {
			err = e
		}

		vec, ok := data[key]
		if !ok {
			vec = vector.NewStringVector(0)
			data[key] = vec
		}
		vec.Push(value)
	}

	m = make(map[string][]string)
	for k, vec := range data {
		m[k] = vec.Data()
	}

	return
}
Ejemplo n.º 2
0
func number_to_words(num int) (s string)
{
	components := vector.NewStringVector(0);
	var ones = map[int] string {
		0: "", 1: "one", 2: "two", 3: "three", 4: "four", 5: "five",
		6: "six", 7: "seven", 8: "eight", 9: "nine",
	};
	var teens = map[int] string {
		0: "ten", 1: "eleven", 2: "twelve", 3: "thirteen", 4: "fourteen", 5: "fifteen",
		6: "sixteen", 7: "seventeen", 8: "eighteen", 9: "nineteen",
	};
	var tens = map[int] string {
		2: "twenty", 3: "thirty", 4: "forty", 5: "fifty",
		6: "sixty", 7: "seventy", 8: "eighty", 9: "ninety",
	};
	if num==1000 {
		return "one thousand"
	}
	t := 0;
	if num/100!=0 {
		t=num/100;
		components.Push(ones[t]);
		components.Push("hundred")
	}
	num=num%100;
	if num!=0 && components.Len()>0 { 
		components.Push("and");
		}
	if num/10!=0 {
		t=num/10;
		if t>1 {
			components.Push(tens[t]);
		}
		else {
			if t==1 {
				components.Push(teens[num%10])
			}
		}
	}
	if num<10 || num >19 {
		components.Push(ones[num%10]);
	}
	
	return strings.Join(components.Data(), " ");
}