// From stackoverflow: http://stackoverflow.com/a/10030772
165440
func reverse(command *bot.Cmd) (msg string, err error) {
	runes := []rune(command.FullArg)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	msg = string(runes)
	return
}
521661
func URL() string {
	url := "http" + RandString([]string{"s", ""}) + "://www."
	url += DomainName()

	// Slugs
	num := Number(1, 4)
	slug := make([]string, num)
	for i := 0; i < num; i++ {
		slug[i] = BS()
	}
	url += "/" + strings.ToLower(strings.Join(slug, "/"))

	return url
}
643526
func (e *Error) Error() string {
	loc := ""
	if e.Path != "" {
		line := ""
		if e.Line != 0 {
			line = fmt.Sprintf(":%d", e.Line)
		}
		loc = fmt.Sprintf("(in %s%s)", e.Path, line)
	}
	header := loc
	if e.Title != "" {
		if loc != "" {
			header = fmt.Sprintf("%s %s: ", e.Title, loc)
		} else {
			header = fmt.Sprintf("%s: ", e.Title)
		}
	}
	return fmt.Sprintf("%s%s Stack: %s", header, e.Description, e.Stack)
}
340219
func (c *Comment) APIFormat() *api.Comment {
	return &api.Comment{
		ID:      c.ID,
		HTMLURL: c.HTMLURL(),
		Poster:  c.Poster.APIFormat(),
		Body:    c.Content,
		Created: c.Created,
		Updated: c.Updated,
	}
}
456790
func (r *Reply) Float64() (float64, error) {
	if r.Type == ErrorReply {
		return 0, r.Err
	}
	if r.Type == BulkReply {
		s, err := r.Str()
		if err != nil {
			return 0, err
		}
		f64, err := strconv.ParseFloat(s, 64)
		if err != nil {
			return 0, errors.New("failed to parse float value from string value")
		} else {
			return f64, nil
		}
	}

	return 0, errors.New("float value is not available for this reply type")
}
1304541
func (e *Error) Stack() string {
	if len(e.stacks) > 0 {
		var frames []string
		for _, stack := range e.stacks {
			if frames == nil {
				frames = make([]string, 0, len(stack))
			} else {
				frames = append(frames, "----- attached stack -----")
			}
			for _, f := range stack {
				frames = append(frames, f.String())
			}
		}
		return strings.Join(frames, "\n")
	}
	return ""
}
1068600
func (c *Client) StackInfo(stackIdentity string) (*Stack, error) {
	var stack Stack
	return &stack, c.Get(&stack, "/stacks/"+stackIdentity)
}
1158201
func commentTextFn(v string) string {
	const indent = "    "
	var buf bytes.Buffer
	godoc.ToText(&buf, v, indent, "\t", 80-2*len(indent))
	p := buf.Bytes()
	return string(p)
}
804902
func (scope *Scope) Quote(str string) string {
	if strings.Contains(str, ".") {
		newStrs := []string{}
		for _, str := range strings.Split(str, ".") {
			newStrs = append(newStrs, scope.Dialect().Quote(str))
		}
		return strings.Join(newStrs, ".")
	}

	return scope.Dialect().Quote(str)
}
642200
func (sm *ShortMessage) NumbUnsuccess() (int, error) {
	sm.resp.Lock()
	defer sm.resp.Unlock()
	if sm.resp.p == nil {
		return 0, errors.New("Response PDU not available")
	}
	f := sm.resp.p.Fields()[pdufield.NoUnsuccess]
	if f == nil {
		return 0, errors.New("Response PDU does not contain NoUnsuccess field")
	}
	i, err := strconv.Atoi(f.String())
	if err != nil {
		return 0, fmt.Errorf("Failed to convert PDU value to string, error: %s", err.Error())
	}
	return i, nil
}
217447
func (s *StackError) String() string {
	if s.message != "" {
		return s.message
	}

	s.message = fmt.Sprintf("%s\n\t%s",
		s.Composer.String(),
		strings.Join(s.Stacktrace, "\n\t"))

	return s.message
}
633494
func NewStack() (o Stack) {
	var i = &StackItem{}
	for _, line := range bytes.Split(DebugStack(), byteLineDelimiter) {
		// Trim line
		line = bytes.TrimSpace(line)

		// Check line type
		var r [][]string
		if r = regexpFunction.FindAllStringSubmatch(string(line), -1); len(r) > 0 && len(r[0]) > 1 {
			i.Function = r[0][1]
		} else if r = regexpFile.FindAllStringSubmatch(string(line), -1); len(r) > 0 && len(r[0]) > 2 {
			i.Filename = r[0][1]
			i.Line, _ = strconv.Atoi(r[0][2])
			o = append(o, *i)
			i = &StackItem{}
		}
	}
	return
}
1101621
func (pt *ParseTime) RFC8xx1123(value string) (time.Time, error) {
	t, _, err := parseRFC8xx1123(value, pt.location)
	return t, err
}
1352611
func parseComment(t *thing) (*Comment, error) {
	// Reddit makes the replies field a string if it is empty, just to make
	// it harder for programmers who like static type systems.
	value, present := t.Data["replies"]
	if present {
		if str, ok := value.(string); ok && str == "" {
			delete(t.Data, "replies")
		}
	}

	c := &comment{}
	if err := mapstructure.Decode(t.Data, c); err != nil {
		return nil, mapDecodeError(err, t.Data)
	}

	var err error
	if c.Replies.Kind == listingKind {
		c.Comment.Replies, _, _, err = parseListing(&c.Replies)
	}

	c.Comment.Deleted = c.Comment.Body == deletedKey
	return &c.Comment, err
}
1075232
func Stack(err error) error {
	return &stackError{
		cause: err,
		stack: string(debug.StackSkip(2)),
	}
}
924615
func reverseComments(list []Comment) {
	for i, j := 0, len(list)-1; i < j; i, j = i+1, j-1 {
		list[i], list[j] = list[j], list[i]
	}
}
855419
func main() {
	if len(os.Args) != 4 {
		fmt.Fprintf(os.Stderr, "expected 3 arguments, got %d\n", len(os.Args)-1)
		exit.Exit(1)
	}

	// No error checking here, it's a contrived example after all.
	a, _ := strconv.Atoi(os.Args[2])
	b, _ := strconv.Atoi(os.Args[3])

	var op func(int, int) int
	switch os.Args[1] {
	case "add":
		op = add
	case "sub":
		op = sub
	default:
		fmt.Fprintf(os.Stderr, "unknown operation: %s\n", os.Args[1])
		exit.Exit(1)
	}

	fmt.Println(op(a, b))
}