// NewLineTypeTable parses the slice of tags into a table that maps the LineType name to
// the parsed LineType object.
506180
func NewLineTypeTable(tags core.TagSlice) (Table, error) {
	table := make(Table)

	tableSlices, err := TableEntryTags(tags)
	if err != nil {
		return table, err
	}

	for _, slice := range tableSlices {
		ltype, err := NewLineType(slice)
		if err != nil {
			return nil, err
		}
		table[ltype.Name] = ltype
	}

	return table, nil
}
1047899
func NewAliasedTable(name, alias string, model interface{}) *Table {
	t := NewTable(name, model)
	t.Alias = alias
	return t
}
284644
func tableFromStructType(structName string, structType *ast.StructType, packagePrefix string) (*Table, error) {
	normalizedName, err := NormalizeName(structName)
	if err != nil {
		// TODO: This isn't correct, someone could override the name later
		return nil, errors.Wrapf(err, "struct name is invalid")
	}

	t := &Table{
		StructName: structName,
		EntityDefinition: EntityDefinition{
			Name:    normalizedName,
			Columns: []*ColumnDefinition{},
			Indexes: map[string]*IndexDefinition{},
		},
		ColToField: map[string]string{},
		FieldToCol: map[string]string{},
	}
	for _, field := range structType.Fields.List {
		var dosaTag string
		if field.Tag != nil {
			entityTag := reflect.StructTag(strings.Trim(field.Tag.Value, "`"))
			dosaTag = strings.TrimSpace(entityTag.Get(dosaTagKey))
		}
		if dosaTag == "-" { // skip explicitly ignored fields
			continue
		}

		kind, err := parseASTType(field.Type)
		if err != nil {
			return nil, err
		}

		if kind == packagePrefix+"."+entityName || (packagePrefix == "" && kind == entityName) {
			var err error
			if t.EntityDefinition.Name, t.TTL, t.ETL, t.Key, err = parseEntityTag(structName, dosaTag); err != nil {
				return nil, err
			}
		} else {
			for _, fieldName := range field.Names {
				name := fieldName.Name
				if kind == packagePrefix+"."+indexName || (packagePrefix == "" && kind == indexName) {
					indexName, indexKey, err := parseIndexTag(name, dosaTag)
					if err != nil {
						return nil, err
					}
					if _, exist := t.Indexes[indexName]; exist {
						return nil, errors.Errorf("index name is duplicated: %s", indexName)
					}
					t.Indexes[indexName] = &IndexDefinition{Key: indexKey}
				} else {
					firstRune, _ := utf8.DecodeRuneInString(name)
					if unicode.IsLower(firstRune) {
						// skip unexported fields
						continue
					}
					typ, isPointer := stringToDosaType(kind, packagePrefix)
					if typ == Invalid {
						return nil, fmt.Errorf("Column %q has invalid type %q", name, kind)
					}
					cd, err := parseField(typ, isPointer, name, dosaTag)
					if err != nil {
						return nil, errors.Wrapf(err, "column %q", name)
					}
					t.Columns = append(t.Columns, cd)
					t.ColToField[cd.Name] = name
					t.FieldToCol[name] = cd.Name
				}
			}

			if len(field.Names) == 0 {
				if kind == packagePrefix+"."+indexName || (packagePrefix == "" && kind == indexName) {
					indexName, indexKey, err := parseIndexTag("", dosaTag)
					if err != nil {
						return nil, err
					}
					if _, exist := t.Indexes[indexName]; exist {
						return nil, errors.Errorf("index name is duplicated: %s", indexName)
					}
					t.Indexes[indexName] = &IndexDefinition{Key: indexKey}
				}
			}
		}
	}

	if t.Key == nil {
		return nil, errors.Errorf("cannot find dosa.Entity in object %s", t.StructName)
	}

	translateKeyName(t)
	if err := t.EnsureValid(); err != nil {
		return nil, errors.Wrap(err, "failed to parse dosa object")
	}
	return t, nil
}
582987
func Inline(html string) (string, error) {
	result, err := NewInliner(html).Inline()
	if err != nil {
		return "", err
	}

	return result, nil
}
475706
func (r *roffRenderer) Table(out *bytes.Buffer, header []byte, body []byte, columnData []int) {
	out.WriteString(".TS\nallbox;\n")

	out.Write(header)
	out.Write(body)
	out.WriteString("\n.TE\n")
}
416749
func NewLoginFailType(Description string) *LoginFailType {
	s := new(LoginFailType)
	s.Description = Description
	return s
}
327073
func NewFieldTypeFrom(ref *FieldType) *FieldType {
	ft := newFieldType()
	ft.indexed = ref.indexed
	ft.stored = ref.stored
	ft._tokenized = ref._tokenized
	ft.storeTermVectors = ref.storeTermVectors
	ft.storeTermVectorOffsets = ref.storeTermVectorOffsets
	ft.storeTermVectorPositions = ref.storeTermVectorPositions
	ft.storeTermVectorPayloads = ref.storeTermVectorPayloads
	ft._omitNorms = ref._omitNorms
	ft._indexOptions = ref._indexOptions
	ft._docValueType = ref._docValueType
	ft.numericType = ref.numericType
	// Do not copy frozen!
	return ft
}
25964
func (msg *Message) TypeTags() (string, error) {
	if msg == nil {
		return "", fmt.Errorf("message is nil")
	}

	tags := ","
	for _, m := range msg.Arguments {
		s, err := getTypeTag(m)
		if err != nil {
			return "", err
		}
		tags += s
	}

	return tags, nil
}
1335919
func NewRegexLineParser(regexStrs []string) (*RegexLineParser, error) {
	lineRegexes, err := ParseLineRegexes(regexStrs)
	if err != nil {
		return nil, err
	}
	logrus.WithFields(logrus.Fields{
		"lineRegexes": lineRegexes,
	}).Debug("Compiled line regexes")
	return &RegexLineParser{lineRegexes}, nil
}
624648
func NewMatcher(kind types.Type, fn Matcher) TypeMatcher {
	matcher := func(buf []byte) types.Type {
		if fn(buf) {
			return kind
		}
		return types.Unknown
	}

	Matchers[kind] = matcher
	// prepend here so any user defined matchers get added first
	MatcherKeys = append([]types.Type{kind}, MatcherKeys...)
	return matcher
}
861365
func NewLineScanner(r io.Reader) *LineScanner {
	br := bufio.NewReader(r)
	ls := &LineScanner{
		Reader: br,
	}
	return ls
}
834140
func NewInlineKeyboardButtonData(text, data string) InlineKeyboardButton {
	return InlineKeyboardButton{
		Text:         text,
		CallbackData: &data,
	}
}
406029
func (b *Buffer) NewLine(copyMargin bool) {
	if copyMargin {
		b.InsertText("\n"+b.Document().leadingWhitespaceInCurrentLine(), false, true)
	} else {
		b.InsertText("\n", false, true)
	}
}
879507
func newFieldType(tp *types.FieldType) *types.FieldType {
	switch tp.Tp {
	// To avoid overflow error.
	case mysql.TypeTiny, mysql.TypeShort, mysql.TypeInt24, mysql.TypeLong, mysql.TypeLonglong:
		newTp := types.NewFieldType(mysql.TypeLonglong)
		newTp.Flag = tp.Flag
		newTp.Charset = tp.Charset
		return newTp
	// To avoid data truncate error.
	case mysql.TypeFloat, mysql.TypeDouble, mysql.TypeBlob, mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeLongBlob,
		mysql.TypeString, mysql.TypeVarchar, mysql.TypeVarString:
		newTp := types.NewFieldType(tp.Tp)
		newTp.Charset = tp.Charset
		return newTp
	default:
		return tp
	}
}
336012
func (c *ContentObj) AppendStreamSetLineType(t string) {
	var cache cacheContentLineType
	cache.lineType = t
	c.listCache.append(&cache)

}
531422
func TableEntryTags(tags core.TagSlice) ([]core.TagSlice, error) {
	groups := core.TagGroups(tags, 0)
	lastIndex := len(groups) - 1
	first := groups[0][0].Value.ToString()
	last := groups[lastIndex][0].Value.ToString()

	if first != "TABLE" || last != "ENDTAB" {
		return []core.TagSlice{},
			errors.New("Invalid table. Missing TABLE AND/OR ENDTAB tags.")
	}

	return groups[1:lastIndex], nil
}
406991
func typeTag(structType reflect.Type) byte {
	var tag byte
	var tagStr string
	tagStr = structType.Field(0).Tag.Get("sshtype")
	i, err := strconv.Atoi(tagStr)
	if err == nil {
		tag = byte(i)
	}
	return tag
}