// NewVersion parses a given version and returns an instance of Version or
// an error if unable to parse the version.
167447
func NewVersion(v string) (*Version, error) {
	m := versionRegex.FindStringSubmatch(v)
	if m == nil {
		return nil, ErrInvalidSemVer
	}

	sv := &Version{
		metadata: m[8],
		pre:      m[5],
		original: v,
	}

	var temp int64
	temp, err := strconv.ParseInt(m[1], 10, 64)
	if err != nil {
		return nil, fmt.Errorf("Error parsing version segment: %s", err)
	}
	sv.major = temp

	if m[2] != "" {
		temp, err = strconv.ParseInt(strings.TrimPrefix(m[2], "."), 10, 64)
		if err != nil {
			return nil, fmt.Errorf("Error parsing version segment: %s", err)
		}
		sv.minor = temp
	} else {
		sv.minor = 0
	}

	if m[3] != "" {
		temp, err = strconv.ParseInt(strings.TrimPrefix(m[3], "."), 10, 64)
		if err != nil {
			return nil, fmt.Errorf("Error parsing version segment: %s", err)
		}
		sv.patch = temp
	} else {
		sv.patch = 0
	}

	return sv, nil
}
818100
func parseVersion(v string) (semver.Version, error) {
	parts := strings.Split(v, ".")
	var err error
	for i := len(parts); i > 0; i-- {
		var ver semver.Version
		ver, err = semver.ParseTolerant(strings.Join(parts[:i], "."))
		if err == nil {
			return ver, nil
		}
	}
	return semver.Version{}, err
}
1161431
func (s *UpdateConnectivityInfoOutput) SetVersion(v string) *UpdateConnectivityInfoOutput {
	s.Version = &v
	return s
}
985870
func (s *CreateConnectorDefinitionVersionOutput) SetVersion(v string) *CreateConnectorDefinitionVersionOutput {
	s.Version = &v
	return s
}
717203
func (s *UpdateScriptInput) SetVersion(v string) *UpdateScriptInput {
	s.Version = &v
	return s
}
894114
func (c *Client) CreateVersion(i *CreateVersionInput) (*Version, error) {
	if i.Service == "" {
		return nil, ErrMissingService
	}

	path := fmt.Sprintf("/service/%s/version", i.Service)
	resp, err := c.PostForm(path, i, nil)
	if err != nil {
		return nil, err
	}

	var e *Version
	if err := decodeJSON(&e, resp.Body); err != nil {
		return nil, err
	}
	return e, nil
}
848948
func (s *BaseConfigurationItem) SetVersion(v string) *BaseConfigurationItem {
	s.Version = &v
	return s
}
893227
func NewCompleteVersion(s string) (*CompleteVersion, error) {
	var err error
	epoch := 0
	rel := Version("")

	// handle possible epoch
	versions := strings.Split(s, ":")
	if len(versions) > 2 {
		return nil, fmt.Errorf("invalid version format: %s", s)
	}

	if len(versions) > 1 {
		epoch, err = strconv.Atoi(versions[0])
		if err != nil {
			return nil, err
		}
	}

	// handle possible rel
	versions = strings.Split(versions[len(versions)-1], "-")
	if len(versions) > 2 {
		return nil, fmt.Errorf("invalid version format: %s", s)
	}

	if len(versions) > 1 {
		rel = Version(versions[1])
	}

	// finally check that the actual version is valid
	if validPkgver(versions[0]) {
		return &CompleteVersion{
			Version: Version(versions[0]),
			Epoch:   uint8(epoch),
			Pkgrel:  rel,
		}, nil
	}

	return nil, fmt.Errorf("invalid version format: %s", s)
}
365169
func (s *RulesPackage) SetVersion(v string) *RulesPackage {
	s.Version = &v
	return s
}
837903
func parseVersion(s string) (Version, error) {
	if validPkgver(s) {
		return Version(s), nil
	}

	return "", fmt.Errorf("invalid version string: %s", s)
}
1037913
func (s *SearchService) Version(version bool) *SearchService {
	s.searchSource = s.searchSource.Version(version)
	return s
}
412755
func NewUserVersion(uid keybase1.UID, eldestSeqno keybase1.Seqno) keybase1.UserVersion {
	return keybase1.NewUserVersion(uid, eldestSeqno)
}
674749
func (s *UpdateApiOutput) SetVersion(v string) *UpdateApiOutput {
	s.Version = &v
	return s
}
825414
func (s *CreateRestApiInput) SetVersion(v string) *CreateRestApiInput {
	s.Version = &v
	return s
}
1325297
func defaultVersion(versions []PackageVersion) Version {
	var versionStrings []string
	for _, version := range versions {
		versionStrings = append(versionStrings, version.Version.String())
	}
	sort.Sort(sortableSliceOfVersions(versionStrings))
	return Version(versionStrings[len(versionStrings)-1])
}
96042
func (s *CreateClusterInput) SetVersion(v string) *CreateClusterInput {
	s.Version = &v
	return s
}
553662
func (s *PutIntentOutput) SetVersion(v string) *PutIntentOutput {
	s.Version = &v
	return s
}