// ConvertODT converts a ODT file to text
422636
func ConvertODT(r io.Reader) (string, map[string]string, error) {
	meta := make(map[string]string)
	var textBody string

	b, err := ioutil.ReadAll(r)
	if err != nil {
		return "", nil, err
	}
	zr, err := zip.NewReader(bytes.NewReader(b), int64(len(b)))
	if err != nil {
		return "", nil, fmt.Errorf("error unzipping data: %v", err)
	}

	for _, f := range zr.File {
		switch f.Name {
		case "meta.xml":
			rc, err := f.Open()
			if err != nil {
				return "", nil, fmt.Errorf("error extracting '%v' from archive: %v", f.Name, err)
			}
			defer rc.Close()

			info, err := XMLToMap(rc)
			if err != nil {
				return "", nil, fmt.Errorf("error parsing '%v': %v", f.Name, err)
			}

			if tmp, ok := info["creator"]; ok {
				meta["Author"] = tmp
			}
			if tmp, ok := info["date"]; ok {
				if t, err := time.Parse("2006-01-02T15:04:05", tmp); err == nil {
					meta["ModifiedDate"] = fmt.Sprintf("%d", t.Unix())
				}
			}
			if tmp, ok := info["creation-date"]; ok {
				if t, err := time.Parse("2006-01-02T15:04:05", tmp); err == nil {
					meta["CreatedDate"] = fmt.Sprintf("%d", t.Unix())
				}
			}

		case "content.xml":
			rc, err := f.Open()
			if err != nil {
				return "", nil, fmt.Errorf("error extracting '%v' from archive: %v", f.Name, err)
			}
			defer rc.Close()

			textBody, err = XMLToText(rc, []string{"br", "p", "tab"}, []string{}, true)
			if err != nil {
				return "", nil, fmt.Errorf("error parsing '%v': %v", f.Name, err)
			}
		}
	}

	return textBody, meta, nil
}
360633
func OpenReaderAt(r io.ReaderAt, size int64) (*File, error) {
	return OpenReaderAtWithRowLimit(r, size, NoRowLimit)
}
643828
func convertDatapointToStatsd(datapoint producers.Datapoint) (string, string, bool) {
	val, err := normalize(datapoint.Value)
	if err != nil {
		// This is only debug-level because we expect many NaNs in regular usage
		log.Debugf("Metric %s failed to convert: %q", datapoint.Name, err)
		return "", "", false
	}
	return datapoint.Name, fmt.Sprintf("%d|g", val), true
}
399824
func ConvertSavedFile(dockerSavedFile string, config FileConfig) ([]string, error) {
	config.initLogger()

	f, err := os.Open(dockerSavedFile)
	if err != nil {
		return nil, fmt.Errorf("error opening file: %v", err)
	}
	defer f.Close()

	return (&converter{
		backend:   file.NewFileBackend(f, config.Debug, config.Info),
		dockerURL: config.DockerURL,
		config:    config.CommonConfig,
	}).convert()
}
215554
func (d Decoder) ConvertStringOK(s string) (result string, ok bool) {
	bytes := []byte(s)
	runes := make([]rune, len(s))
	destPos := 0
	ok = true

	for len(bytes) > 0 {
		c, size, status := d(bytes)

		switch status {
		case STATE_ONLY:
			bytes = bytes[size:]
			continue

		case NO_ROOM:
			c = 0xfffd
			size = len(bytes)
			ok = false

		case INVALID_CHAR:
			ok = false
		}

		bytes = bytes[size:]
		runes[destPos] = c
		destPos++
	}

	return string(runes[:destPos]), ok
}
575862
func ConvertImage(r io.Reader) (string, map[string]string, error) {
	return "", nil, fmt.Errorf("docconv not built with `ocr` build tag")
}
179856
func (d Decoder) ConvertString(s string) string {
	bytes := []byte(s)
	runes := make([]rune, len(s))
	destPos := 0

	for len(bytes) > 0 {
		c, size, status := d(bytes)

		if status == STATE_ONLY {
			bytes = bytes[size:]
			continue
		}

		if status == NO_ROOM {
			c = 0xfffd
			size = len(bytes)
			status = INVALID_CHAR
		}

		bytes = bytes[size:]
		runes[destPos] = c
		destPos++
	}

	return string(runes[:destPos])
}
968613
func (model *Model) convertOldFormat(filename string) error {
	oldmodel := new(OldModel)
	f, err := os.Open(filename)
	if err != nil {
		return err
	}
	defer f.Close()
	d := json.NewDecoder(f)
	err = d.Decode(oldmodel)
	if err != nil {
		return err
	}

	// Correct for old models pre divergence measure
	if model.SuffDivergenceThreshold == 0 {
		model.SuffDivergenceThreshold = SuffDivergenceThresholdDefault
	}

	// Convert fields
	model.Maxcount = oldmodel.Maxcount
	model.Suggest = oldmodel.Suggest
	model.Depth = oldmodel.Depth
	model.Threshold = oldmodel.Threshold
	model.UseAutocomplete = oldmodel.UseAutocomplete

	// Convert the old counts
	if len(oldmodel.Data) > 0 {
		model.Data = make(map[string]*Counts, len(oldmodel.Data))
		for term, cc := range oldmodel.Data {
			model.Data[term] = &Counts{cc, 0}
		}
	}
	return nil
}
1256180
func (b *TodoJSONBuilder) Convert(orig *Todo) (*TodoJSON, error) {
	if orig == nil {
		return nil, nil
	}
	ret := &TodoJSON{}

	for _, info := range b._properties {
		if err := info.Encoder(orig, ret); err != nil {
			return nil, err
		}
	}

	return ret, nil
}
1316227
func (d Duration) ConvertToTime(tp uint8) (Time, error) {
	year, month, day := gotime.Now().Date()
	// just use current year, month and day.
	n := gotime.Date(year, month, day, 0, 0, 0, 0, gotime.Local)
	n = n.Add(d.Duration)

	t := Time{
		Time: FromGoTime(n),
		Type: mysql.TypeDatetime,
		Fsp:  d.Fsp,
	}

	return t.Convert(tp)
}
6783
func convert(a *AutomatonBuilder, s *dfsaState, visited map[*dfsaState]int) int {
	panic("not implemented yet")
}
77944
func MarkdownToTextNoMetadata(markdown []byte, opts *Options) []byte {
	opts = resolveOpts(opts)
	rend := &renderer{
		width:             opts.Width,
		color:             opts.Color,
		tableAlignOptions: opts.TableAlignOptions,
		headerPrefix:      opts.HeaderPrefix,
		headerSuffix:      opts.HeaderSuffix,
	}
	markdown = bytes.Replace(markdown, []byte("\n///\n"), []byte(""), -1)
	txt := blackfriday.Markdown(markdown, rend,
		blackfriday.EXTENSION_NO_INTRA_EMPHASIS|
			blackfriday.EXTENSION_TABLES|
			blackfriday.EXTENSION_FENCED_CODE|
			blackfriday.EXTENSION_AUTOLINK|
			blackfriday.EXTENSION_STRIKETHROUGH|
			blackfriday.EXTENSION_DEFINITION_LISTS)
	for rend.level > 0 {
		txt = append(txt, markIndentStop)
		rend.level--
	}
	if len(txt) > 0 {
		txt = bytes.Replace(txt, []byte(" \n"), []byte(" "), -1)
		txt = bytes.Replace(txt, []byte("\n"), []byte(" "), -1)
		txt = reflow(txt, opts.Indent1, opts.Indent2, rend.width)
		txt = bytes.Replace(txt, []byte{markNBSP}, []byte(" "), -1)
		txt = bytes.Replace(txt, []byte{markLineBreak}, []byte("\n"), -1)
	}
	return txt
}
229147
func (d *Datum) ConvertTo(sc *stmtctx.StatementContext, target *FieldType) (Datum, error) {
	if d.k == KindNull {
		return Datum{}, nil
	}
	switch target.Tp { // TODO: implement mysql types convert when "CAST() AS" syntax are supported.
	case mysql.TypeTiny, mysql.TypeShort, mysql.TypeInt24, mysql.TypeLong, mysql.TypeLonglong:
		unsigned := mysql.HasUnsignedFlag(target.Flag)
		if unsigned {
			return d.convertToUint(sc, target)
		}
		return d.convertToInt(sc, target)
	case mysql.TypeFloat, mysql.TypeDouble:
		return d.convertToFloat(sc, target)
	case mysql.TypeBlob, mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeLongBlob,
		mysql.TypeString, mysql.TypeVarchar, mysql.TypeVarString:
		return d.convertToString(sc, target)
	case mysql.TypeTimestamp:
		return d.convertToMysqlTimestamp(sc, target)
	case mysql.TypeDatetime, mysql.TypeDate:
		return d.convertToMysqlTime(sc, target)
	case mysql.TypeDuration:
		return d.convertToMysqlDuration(sc, target)
	case mysql.TypeNewDecimal:
		return d.convertToMysqlDecimal(sc, target)
	case mysql.TypeYear:
		return d.convertToMysqlYear(sc, target)
	case mysql.TypeEnum:
		return d.convertToMysqlEnum(sc, target)
	case mysql.TypeBit:
		return d.convertToMysqlBit(sc, target)
	case mysql.TypeSet:
		return d.convertToMysqlSet(sc, target)
	case mysql.TypeJSON:
		return d.convertToMysqlJSON(sc, target)
	case mysql.TypeNull:
		return Datum{}, nil
	default:
		panic("should never happen")
	}
}
290873
func (id ULID) MarshalTextTo(dst []byte) error {
	// Optimized unrolled loop ahead.
	// From https://github.com/RobThree/NUlid

	if len(dst) != EncodedSize {
		return ErrBufferSize
	}

	// 10 byte timestamp
	dst[0] = Encoding[(id[0]&224)>>5]
	dst[1] = Encoding[id[0]&31]
	dst[2] = Encoding[(id[1]&248)>>3]
	dst[3] = Encoding[((id[1]&7)<<2)|((id[2]&192)>>6)]
	dst[4] = Encoding[(id[2]&62)>>1]
	dst[5] = Encoding[((id[2]&1)<<4)|((id[3]&240)>>4)]
	dst[6] = Encoding[((id[3]&15)<<1)|((id[4]&128)>>7)]
	dst[7] = Encoding[(id[4]&124)>>2]
	dst[8] = Encoding[((id[4]&3)<<3)|((id[5]&224)>>5)]
	dst[9] = Encoding[id[5]&31]

	// 16 bytes of entropy
	dst[10] = Encoding[(id[6]&248)>>3]
	dst[11] = Encoding[((id[6]&7)<<2)|((id[7]&192)>>6)]
	dst[12] = Encoding[(id[7]&62)>>1]
	dst[13] = Encoding[((id[7]&1)<<4)|((id[8]&240)>>4)]
	dst[14] = Encoding[((id[8]&15)<<1)|((id[9]&128)>>7)]
	dst[15] = Encoding[(id[9]&124)>>2]
	dst[16] = Encoding[((id[9]&3)<<3)|((id[10]&224)>>5)]
	dst[17] = Encoding[id[10]&31]
	dst[18] = Encoding[(id[11]&248)>>3]
	dst[19] = Encoding[((id[11]&7)<<2)|((id[12]&192)>>6)]
	dst[20] = Encoding[(id[12]&62)>>1]
	dst[21] = Encoding[((id[12]&1)<<4)|((id[13]&240)>>4)]
	dst[22] = Encoding[((id[13]&15)<<1)|((id[14]&128)>>7)]
	dst[23] = Encoding[(id[14]&124)>>2]
	dst[24] = Encoding[((id[14]&3)<<3)|((id[15]&224)>>5)]
	dst[25] = Encoding[id[15]&31]

	return nil
}
806907
func (parser *Parser) ParseOneStmt(sql, charset, collation string) (ast.StmtNode, error) {
	stmts, err := parser.Parse(sql, charset, collation)
	if err != nil {
		return nil, errors.Trace(err)
	}
	if len(stmts) != 1 {
		return nil, ErrSyntax
	}
	ast.SetFlag(stmts[0])
	return stmts[0], nil
}
97460
func (t ListType) ConvertToModel(value interface{}) (interface{}, error) {
	// the assumption is that work item types do not change over time...only new ones can be created
	return ConvertList(func(fieldType FieldType, value interface{}) (interface{}, error) {
		return fieldType.ConvertToModel(value)
	}, t.ComponentType, value)

}
844574
func (b *BatchBuilder) AddStmt(stmt string, names []string) *BatchBuilder {
	b.stmts = append(b.stmts, stmt)
	b.names = append(b.names, names...)
	return b
}