// Inserts ~tag just before the extension of the filename.
174596
func TagFilename(name, tag string) string {
	dir, file := filepath.Dir(name), filepath.Base(name)
	ext := filepath.Ext(file)
	withoutExt := file[:len(file)-len(ext)]
	return filepath.Join(dir, withoutExt+"~"+tag+ext)
}
39057
func (store *store) AddTag(ref reference.Named, id digest.Digest, force bool) error {
	if _, isCanonical := ref.(reference.Canonical); isCanonical {
		return errors.WithStack(invalidTagError("refusing to create a tag with a digest reference"))
	}
	return store.addReference(reference.TagNameOnly(ref), id, force)
}
955708
func (tag *Tag) Save() error {
	file, ok := tag.reader.(*os.File)
	if !ok {
		return ErrNoFile
	}

	// Get original file mode.
	originalFile := file
	originalStat, err := originalFile.Stat()
	if err != nil {
		return err
	}

	// Create a temp file for mp3 file, which will contain new tag.
	name := file.Name() + "-id3v2"
	newFile, err := os.OpenFile(name, os.O_RDWR|os.O_CREATE, originalStat.Mode())
	if err != nil {
		return err
	}

	// Make sure we clean up the temp file if it's still around.
	// tempfileShouldBeRemoved created only for performance
	// improvement to prevent calling redundant Remove syscalls if file is moved
	// and is not need to be removed.
	tempfileShouldBeRemoved := true
	defer func() {
		if tempfileShouldBeRemoved {
			os.Remove(newFile.Name())
		}
	}()

	// Write tag in new file.
	tagSize, err := tag.WriteTo(newFile)
	if err != nil {
		return err
	}

	// Seek to a music part of original file.
	if _, err = originalFile.Seek(tag.originalSize, os.SEEK_SET); err != nil {
		return err
	}

	// Write to new file the music part.
	buf := getByteSlice(128 * 1024)
	defer putByteSlice(buf)
	if _, err = io.CopyBuffer(newFile, originalFile, buf); err != nil {
		return err
	}

	// Close files to allow replacing.
	newFile.Close()
	originalFile.Close()

	// Replace original file with new file.
	if err = os.Rename(newFile.Name(), originalFile.Name()); err != nil {
		return err
	}
	tempfileShouldBeRemoved = false

	// Set tag.reader to new file with original name.
	tag.reader, err = os.Open(originalFile.Name())
	if err != nil {
		return err
	}

	// Set tag.originalSize to new frames size.
	tag.originalSize = tagSize

	return nil
}
1112030
func (f *Field) Tag(key string) string {
	return f.field.Tag.Get(key)
}
450201
func (c *Manager) AttachTag(ctx context.Context, tagID string, ref mo.Reference) error {
	id, err := c.tagID(ctx, tagID)
	if err != nil {
		return err
	}
	spec := internal.NewAssociation(ref)
	url := internal.URL(c, internal.AssociationPath).WithID(id).WithAction("attach")
	return c.Do(ctx, url.Request(http.MethodPost, spec), nil)
}
496751
func TagName(tag int) string {
	if (tag & TinyStrTagMask) == TinyStrTag {
		return "String"
	}
	switch tag {
	case NullTag:
		return "Null"
	case BoolTag:
		return "Bool"
	case Int8Tag:
		return "Int8"
	case Int16Tag:
		return "Int16"
	case Int32Tag:
		return "Int32"
	case Int64Tag:
		return "Int64"
	case Float32Tag:
		return "Float32"
	case Float64Tag:
		return "Float64"
	case BytesTag:
		return "Bytes"
	case StringTag:
		return "String"
	case TimestampTag:
		return "Timestamp"
	case SymbolTag:
		return "Symbol"
	case UUIDTag:
		return "UUID"
	case ArrayTag:
		return "Array"
	case MapTag:
		return "Map"
	case StructTag:
		return "Struct"
	case AnyTag:
		return "Any"
	case EnumTag:
		return "Enum"
	default:
		return fmt.Sprintf("0x%02x", tag)
	}
}
263811
func (c Context) Markdown(filename string) (string, error) {
	body, err := c.Include(filename)
	if err != nil {
		return "", err
	}
	renderer := blackfriday.HtmlRenderer(0, "", "")
	extns := 0
	extns |= blackfriday.EXTENSION_TABLES
	extns |= blackfriday.EXTENSION_FENCED_CODE
	extns |= blackfriday.EXTENSION_STRIKETHROUGH
	extns |= blackfriday.EXTENSION_DEFINITION_LISTS
	markdown := blackfriday.Markdown([]byte(body), renderer, extns)

	return string(markdown), nil
}
696580
func (fs *FileSet) TagValueIterator(name, key []byte) TagValueIterator {
	a := make([]TagValueIterator, 0, len(fs.files))
	for _, f := range fs.files {
		itr := f.TagValueIterator(name, key)
		if itr != nil {
			a = append(a, itr)
		}
	}
	return MergeTagValueIterators(a...)
}
216614
func (r *Record) Tag(tag []byte) (v Aux, ok bool) {
	if len(tag) < 2 {
		panic("sam: tag too short")
	}
	for _, aux := range r.AuxFields {
		if aux.matches(tag) {
			return aux, true
		}
	}
	return nil, false
}
267475
func (o *extHandle) AddExt(rt reflect.Type, tag byte,
	encfn func(reflect.Value) ([]byte, error),
	decfn func(reflect.Value, []byte) error) (err error) {
	if encfn == nil || decfn == nil {
		return o.SetExt(rt, uint64(tag), nil)
	}
	return o.SetExt(rt, uint64(tag), addExtWrapper{encfn, decfn})
}
429985
func (tn *tagNode) Tag() []string {
	out := make([]string, len(tn.tag))
	copy(out, tn.tag)
	return out
}
673825
func escapeTag(tag reflect.StructTag) string {
	t := string(tag)
	if strings.ContainsRune(t, '`') {
		// there are ` in the string; we can't use ` to enclose the string
		return strconv.Quote(t)
	}
	return "`" + t + "`"
}
844077
func Dir(dataDir string, tag names.Tag) string {
	// Note: must use path, not filepath, as this
	// function is used by the client on Windows.
	return path.Join(BaseDir(dataDir), tag.String())
}
568342
func (tag *Tag) Close() error {
	file, ok := tag.reader.(*os.File)
	if !ok {
		return ErrNoFile
	}
	return file.Close()
}
280120
func (_m *DFS) Tag(snapshotID string, tagName string) error {
	ret := _m.Called(snapshotID, tagName)

	var r0 error
	if rf, ok := ret.Get(0).(func(string, string) error); ok {
		r0 = rf(snapshotID, tagName)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
1174066
func (t *Tag) Finalize() {
	if t.noFinalize {
		return
	}
	if t.Name != nil {
		t.Name.Finalize()
		t.Name = nil
	}
	if t.Value != nil {
		t.Value.Finalize()
		t.Value = nil
	}
}
443795
func (t *Tags) Add(tag string) error {
	ts := *t
	trim := strings.TrimSpace(tag)
	if trim == "" {
		return e.New(e.ErrEmptyString)
	}
	if err := CheckTag(trim); err != nil {
		return e.Forward(err)
	}
	i := sort.SearchStrings(ts, trim)
	if i >= ts.Len() || ts[i] != trim { // Not found
		//ts = append(ts, trim)
		//sort.Strings(ts)
		ts = append(ts[:i], append(Tags{trim}, ts[i:]...)...)
	} else {
		return e.New(ErrTagExist)
	}
	*t = ts
	return nil
}