func (t *Version) unmarshalText(str []byte) error {
	var idx, fieldNum, column int
	var strlen = len(str)

	if strlen > 1 && str[idx] == 'v' {
		idx++
	}

	for idx < strlen {
		r := str[idx]
		switch {
		case r == '.':
			idx++
			column++
			if column >= 4 || idx >= strlen {
				return errTooManyColumns
			}
			fieldNum++
			fallthrough
		case isNumeric(r):
			idxDelta, n := atoui(str[idx:])
			if idxDelta == 0 || idxDelta >= 10 { // strlen(maxInt) is 10
				return errInvalidVersionString
			}
			t.version[fieldNum] = int32(n)

			idx += idxDelta
		case r == '-' || r == '_':
			idx++
			if idx < strlen && isNumeric(str[idx]) {
				column = 0
				switch {
				case fieldNum < idxReleaseType:
					fieldNum = idxReleaseType + 1
				case fieldNum < idxSpecifierType:
					fieldNum = idxSpecifierType + 1
				default:
					return errInvalidVersionString
				}
				continue
			}
			fallthrough
		case isSmallLetter(r):
			toIdx := idx + 1
			for ; toIdx < strlen && isSmallLetter(str[toIdx]); toIdx++ {
			}

			if toIdx > strlen {
				return errInvalidVersionString
			}
			typ, known := releaseValue[string(str[idx:toIdx])]
			if !known {
				return errInvalidVersionString
			}
			switch {
			case fieldNum < idxReleaseType:
				fieldNum = idxReleaseType
			case fieldNum < idxSpecifierType:
				fieldNum = idxSpecifierType
			default:
				return errInvalidVersionString
			}
			t.version[fieldNum] = int32(typ)
			if toIdx+1 < strlen && str[toIdx] == '.' {
				toIdx++
			}

			fieldNum++
			column = 0
			idx = toIdx
		case r == '+':
			if strlen < idx+len(buildsuffix)+1 || !bytes.Equal(str[idx:idx+len(buildsuffix)], buildsuffix) {
				return errInvalidBuildSuffix
			}
			idx += len(buildsuffix)
			idxDelta, n := atoui(str[idx:])
			if idxDelta > 9 || idx+idxDelta < strlen {
				return errInvalidBuildSuffix
			}
			t.build = int32(n)
			return nil
		default:
			return errInvalidVersionString
		}
	}

	return nil
}
// unmarshalText implements the encoding.TextUnmarshaler interface,
// but assumes the data structure is pristine.
unmarshalText implements the encoding.TextUnmarshaler interface,
but assumes the data structure is pristine.
// unmarshalText implements the encoding . TextUnmarshaler interface // but assumes the data structure is pristine .
func (t *Version) unmarshalText(str []byte) error {
	var idx, fieldNum, column int
	var strlen = len(str)
	if strlen > 1 && str[idx] == 'v' {
		idx++
	}
	for idx < strlen {
		r := str[idx]
		switch {
		case r == '.':
			idx++
			column++
			if column >= 4 || idx >= strlen {
				return errTooManyColumns
			}
			fieldNum++
			fallthrough
		case isNumeric(r):
			idxDelta, n := atoui(str[idx:])
			if idxDelta == 0 || idxDelta >= 10 { 
				return errInvalidVersionString
			}
			t.version[fieldNum] = int32(n)
			idx += idxDelta
		case r == '-' || r == '_':
			idx++
			if idx < strlen && isNumeric(str[idx]) {
				column = 0
				switch {
				case fieldNum < idxReleaseType:
					fieldNum = idxReleaseType + 1
				case fieldNum < idxSpecifierType:
					fieldNum = idxSpecifierType + 1
				default:
					return errInvalidVersionString
				}
				continue
			}
			fallthrough
		case isSmallLetter(r):
			toIdx := idx + 1
			for ; toIdx < strlen && isSmallLetter(str[toIdx]); toIdx++ {
			}
			if toIdx > strlen {
				return errInvalidVersionString
			}
			typ, known := releaseValue[string(str[idx:toIdx])]
			if !known {
				return errInvalidVersionString
			}
			switch {
			case fieldNum < idxReleaseType:
				fieldNum = idxReleaseType
			case fieldNum < idxSpecifierType:
				fieldNum = idxSpecifierType
			default:
				return errInvalidVersionString
			}
			t.version[fieldNum] = int32(typ)
			if toIdx+1 < strlen && str[toIdx] == '.' {
				toIdx++
			}
			fieldNum++
			column = 0
			idx = toIdx
		case r == '+':
			if strlen < idx+len(buildsuffix)+1 || !bytes.Equal(str[idx:idx+len(buildsuffix)], buildsuffix) {
				return errInvalidBuildSuffix
			}
			idx += len(buildsuffix)
			idxDelta, n := atoui(str[idx:])
			if idxDelta > 9 || idx+idxDelta < strlen {
				return errInvalidBuildSuffix
			}
			t.build = int32(n)
			return nil
		default:
			return errInvalidVersionString
		}
	}
	return nil
}
func ( t * Version ) unmarshalText ( str [ ] byte ) error { var idx , fieldNum , column int var strlen = len ( str ) if strlen > 1 && str [ idx ] == 'v' { idx ++ } for idx < strlen { r := str [ idx ] switch { case r == '.' : idx ++ column ++ if column >= 4 || idx >= strlen { return errTooManyColumns } fieldNum ++ fallthrough case isNumeric ( r ) : idxDelta , n := atoui ( str [ idx : ] ) if idxDelta == 0 || idxDelta >= 10 { return errInvalidVersionString } t . version [ fieldNum ] = int32 ( n ) idx += idxDelta case r == '-' || r == '_' : idx ++ if idx < strlen && isNumeric ( str [ idx ] ) { column = 0 switch { case fieldNum < idxReleaseType : fieldNum = idxReleaseType + 1 case fieldNum < idxSpecifierType : fieldNum = idxSpecifierType + 1 default : return errInvalidVersionString } continue } fallthrough case isSmallLetter ( r ) : toIdx := idx + 1 for ; toIdx < strlen && isSmallLetter ( str [ toIdx ] ) ; toIdx ++ { } if toIdx > strlen { return errInvalidVersionString } typ , known := releaseValue [ string ( str [ idx : toIdx ] ) ] if ! known { return errInvalidVersionString } switch { case fieldNum < idxReleaseType : fieldNum = idxReleaseType case fieldNum < idxSpecifierType : fieldNum = idxSpecifierType default : return errInvalidVersionString } t . version [ fieldNum ] = int32 ( typ ) if toIdx + 1 < strlen && str [ toIdx ] == '.' { toIdx ++ } fieldNum ++ column = 0 idx = toIdx case r == '+' : if strlen < idx + len ( buildsuffix ) + 1 || ! bytes . Equal ( str [ idx : idx + len ( buildsuffix ) ] , buildsuffix ) { return errInvalidBuildSuffix } idx += len ( buildsuffix ) idxDelta , n := atoui ( str [ idx : ] ) if idxDelta > 9 || idx + idxDelta < strlen { return errInvalidBuildSuffix } t . build = int32 ( n ) return nil default : return errInvalidVersionString } } return nil }
unmarshalText implements the encoding.TextUnmarshaler interface,
but assumes the data structure is pristine.
unmarshalText implements the encoding . TextUnmarshaler interface but assumes the data structure is pristine .
// strlen(maxInt) is 10