// parseFormatChartSet provides a function to parse the format settings of the
// chart with default value.
182854
func parseFormatChartSet(formatSet string) (*formatChart, error) {
	format := formatChart{
		Dimension: formatChartDimension{
			Width:  480,
			Height: 290,
		},
		Format: formatPicture{
			FPrintsWithSheet: true,
			FLocksWithSheet:  false,
			NoChangeAspect:   false,
			OffsetX:          0,
			OffsetY:          0,
			XScale:           1.0,
			YScale:           1.0,
		},
		Legend: formatChartLegend{
			Position:      "bottom",
			ShowLegendKey: false,
		},
		Title: formatChartTitle{
			Name: " ",
		},
		ShowBlanksAs: "gap",
	}
	err := json.Unmarshal([]byte(formatSet), &format)
	return &format, err
}
1072914
func parseRange(rangeStr string) ([]uint, error) {
	var values []uint
	if rangeStr == "" {
		return []uint{}, nil
	}

	// split ranges based on "," char
	rangeList := strings.Split(rangeStr, ",")

	for _, subrange := range rangeList {
		minMax := strings.Split(strings.TrimSpace(subrange), "-")
		if len(minMax) == 2 {
			min, err := strconv.Atoi(minMax[0])
			if err != nil {
				log.Errorf("Invalid range: %v", subrange)
				return nil, err
			}
			max, err := strconv.Atoi(minMax[1])
			if err != nil {
				log.Errorf("Invalid range: %v", subrange)
				return nil, err
			}

			// some error checking
			if min > max || min < 0 || max < 0 {
				log.Errorf("Invalid range values: %v", subrange)
				return nil, fmt.Errorf("invalid range values")
			}

			for i := min; i <= max; i++ {
				values = append(values, uint(i))
			}
		} else if len(minMax) == 1 {
			val, err := strconv.Atoi(minMax[0])
			if err != nil {
				log.Errorf("Invalid range: %v", subrange)
				return nil, err
			}

			values = append(values, uint(val))
		} else {
			log.Errorf("Invalid range: %v", subrange)
			return nil, fmt.Errorf("invalid range format")
		}
	}

	return values, nil
}
51236
func ParseText(p *xpp.XMLPullParser) (string, error) {
	var text struct {
		Type     string `xml:"type,attr"`
		InnerXML string `xml:",innerxml"`
	}

	err := p.DecodeElement(&text)
	if err != nil {
		return "", err
	}

	result := text.InnerXML
	result = strings.TrimSpace(result)

	if strings.Contains(result, CDATA_START) {
		return StripCDATA(result), nil
	}

	return DecodeEntities(result)
}
1114546
func (t *Translator) parseFormat(pattern string, includeDecimalDigits bool) *numberFormat {

	processed := false
	if includeDecimalDigits {
		_, processed = numberFormats[pattern]
	} else {
		_, processed = numberFormatsNoDecimals[pattern]
	}

	if !processed {

		format := new(numberFormat)
		patterns := strings.Split(pattern, ";")

		matches := prefixSuffixRegex.FindAllStringSubmatch(patterns[0], -1)
		if len(matches) > 0 {
			if len(matches[0]) > 1 {
				format.positivePrefix = matches[0][1]
			}
			if len(matches[0]) > 2 {
				format.positiveSuffix = matches[0][2]
			}
		}

		// default values for negative prefix & suffix
		format.negativePrefix = string(t.rules.Numbers.Symbols.Negative) + string(format.positivePrefix)
		format.negativeSuffix = format.positiveSuffix

		// see if they are in the pattern
		if len(patterns) > 1 {
			matches = prefixSuffixRegex.FindAllStringSubmatch(patterns[1], -1)

			if len(matches) > 0 {
				if len(matches[0]) > 1 {
					format.negativePrefix = matches[0][1]
				}
				if len(matches[0]) > 2 {
					format.negativeSuffix = matches[0][2]
				}
			}
		}

		pat := patterns[0]

		if strings.Index(pat, "%") != -1 {
			format.multiplier = 100
		} else if strings.Index(pat, "‰") != -1 {
			format.multiplier = 1000
		} else {
			format.multiplier = 1
		}

		pos := strings.Index(pat, ".")

		if pos != -1 {
			pos2 := strings.LastIndex(pat, "0")
			if pos2 > pos {
				format.minDecimalDigits = pos2 - pos
			}

			pos3 := strings.LastIndex(pat, "#")
			if pos3 >= pos2 {
				format.maxDecimalDigits = pos3 - pos
			} else {
				format.maxDecimalDigits = format.minDecimalDigits
			}

			pat = pat[0:pos]
		}

		p := strings.Replace(pat, ",", "", -1)
		pos = strings.Index(p, "0")
		if pos != -1 {
			format.minIntegerDigits = strings.LastIndex(p, "0") - pos + 1
		}

		p = strings.Replace(pat, "#", "0", -1)
		pos = strings.LastIndex(pat, ",")
		if pos != -1 {
			format.groupSizeFinal = strings.LastIndex(p, "0") - pos
			pos2 := strings.LastIndex(p[0:pos], ",")
			if pos2 != -1 {
				format.groupSizeMain = pos - pos2 - 1
			} else {
				format.groupSizeMain = format.groupSizeFinal
			}
		}

		if includeDecimalDigits {
			numberFormats[pattern] = format
		} else {
			format.maxDecimalDigits = 0
			format.minDecimalDigits = 0
			numberFormatsNoDecimals[pattern] = format
		}

	}

	if includeDecimalDigits {
		return numberFormats[pattern]
	}

	return numberFormatsNoDecimals[pattern]
}
1012249
func (o *querySet) ValuesFlat(result *ParamsList, expr string) (int64, error) {
	return o.orm.alias.DbBaser.ReadValues(o.orm.db, o, o.mi, o.cond, []string{expr}, result, o.orm.alias.TZ)
}
1250243
func (c *LinearConfig) CheckAndSetDefaults() error {
	if c.Step == 0 {
		return trace.BadParameter("missing parameter Step")
	}
	if c.Max == 0 {
		return trace.BadParameter("missing parameter Max")
	}
	return nil
}
524587
func (c *configCommand) parseSet(args []string) error {
	file := c.configFile.Path != ""
	if file && len(args) > 0 {
		return errors.New("cannot specify --file and key=value arguments simultaneously")
	}
	c.action = c.setConfig
	if file {
		c.useFile = true
		return nil
	}

	settings, err := keyvalues.Parse(args, true)
	if err != nil {
		return err
	}
	c.values = settings

	return nil
}
928032
func ParseInt(value string, min, max, defaultValue int) (int, error) {
	res, err := ParseInt64(value, int64(min), int64(max), int64(defaultValue))
	return int(res), err
}
171626
func parseFormatStyleSet(style string) (*formatStyle, error) {
	format := formatStyle{
		DecimalPlaces: 2,
	}
	err := json.Unmarshal([]byte(style), &format)
	return &format, err
}
945783
func parseFormatTableSet(formatSet string) (*formatTable, error) {
	format := formatTable{
		TableStyle:     "",
		ShowRowStripes: true,
	}
	err := json.Unmarshal(parseFormatSet(formatSet), &format)
	return &format, err
}
951954
func (f RegexFormatChecker) IsFormat(input interface{}) bool {
	asString, ok := input.(string)
	if !ok {
		return false
	}

	if asString == "" {
		return true
	}
	_, err := regexp.Compile(asString)
	return err == nil
}
978859
func ValidateMatchAll(patterns ...string) FieldValidatorFunc {
	prx := make([]*regexp.Regexp, len(patterns))

	for i, rxs := range patterns {
		prx[i] = regexp.MustCompile(rxs)
	}

	return func(value interface{}) error {
		for _, rx := range prx {
			if !rx.MatchString(typeutil.String(value)) {
				return fmt.Errorf("Value does not match pattern %q", rx.String())
			}
		}

		return nil
	}
}
607810
func (t *Translator) parseDateTimeFormat(pattern string) ([]*datetimePatternComponent, error) {
	// every thing between single quotes should become a literal
	// all non a-z, A-Z characters become a literal
	// everything else, repeat character sequences become a component
	format := []*datetimePatternComponent{}
	for i := 0; i < len(pattern); {
		char := pattern[i : i+1]

		skip := false
		// for units we don't support yet, just skip over them
		for _, r := range datetimeFormatUnitCutset {
			if char == string(r) {
				skip = true
				break
			}
		}

		if skip {
			i++
			continue
		}

		if char == string(datetimeFormatLiteral) {
			// find the next single quote
			// create a literal out of everything between the quotes
			// and set i to the position after the second quote

			if i == len(pattern)-1 {
				return []*datetimePatternComponent{}, translatorError{message: "malformed datetime format"}
			}

			nextQuote := strings.Index(pattern[i+1:], string(datetimeFormatLiteral))
			if nextQuote == -1 {
				return []*datetimePatternComponent{}, translatorError{message: "malformed datetime format"}
			}

			component := &datetimePatternComponent{
				pattern:       pattern[i+1 : nextQuote+i+1],
				componentType: datetimePatternComponentLiteral,
			}

			format = append(format, component)
			i = nextQuote + i + 2
			continue

		}
		if (char >= "a" && char <= "z") || (char >= "A" && char <= "Z") {
			// this represents a format unit
			// find the entire sequence of the same character
			endChar := lastSequenceIndex(pattern[i:]) + i

			component := &datetimePatternComponent{
				pattern:       pattern[i : endChar+1],
				componentType: datetimePatternComponentUnit,
			}

			format = append(format, component)
			i = endChar + 1
			continue

		}
		if char == string(datetimeFormatTimeSeparator) {
			component := &datetimePatternComponent{
				pattern:       t.rules.DateTime.TimeSeparator,
				componentType: datetimePatternComponentLiteral,
			}
			format = append(format, component)
			i++
			continue

		}

		component := &datetimePatternComponent{
			pattern:       char,
			componentType: datetimePatternComponentLiteral,
		}

		format = append(format, component)
		i++
		continue

	}

	return format, nil
}
1262616
func (s *PercolateService) PercolateFormat(percolateFormat string) *PercolateService {
	s.percolateFormat = percolateFormat
	return s
}
936698
func ParseStrict(datestr string) (time.Time, error) {
	p, err := parseTime(datestr, nil)
	if err != nil {
		return time.Time{}, err
	}
	if p.ambiguousMD {
		return time.Time{}, ErrAmbiguousMMDD
	}
	return p.parse()
}
303546
func (c *SearchCriteria) ParseWithCharset(fields []interface{}, charsetReader func(io.Reader) io.Reader) error {
	for len(fields) > 0 {
		var err error
		if fields, err = c.parseField(fields, charsetReader); err != nil {
			return err
		}
	}
	return nil
}
636176
func parseInputValueDef(parser *Parser) (interface{}, error) {
	var (
		description *ast.StringValue
		name        *ast.Name
		ttype       ast.Type
		directives  []*ast.Directive
		err         error
	)
	start := parser.Token.Start
	if description, err = parseDescription(parser); err != nil {
		return nil, err
	}
	if name, err = parseName(parser); err != nil {
		return nil, err
	}
	if _, err = expect(parser, lexer.COLON); err != nil {
		return nil, err
	}
	if ttype, err = parseType(parser); err != nil {
		return nil, err
	}
	var defaultValue ast.Value
	if skp, err := skip(parser, lexer.EQUALS); err != nil {
		return nil, err
	} else if skp {
		val, err := parseConstValue(parser)
		if err != nil {
			return nil, err
		}
		if val, ok := val.(ast.Value); ok {
			defaultValue = val
		}
	}
	if directives, err = parseDirectives(parser); err != nil {
		return nil, err
	}
	return ast.NewInputValueDefinition(&ast.InputValueDefinition{
		Name:         name,
		Description:  description,
		Type:         ttype,
		DefaultValue: defaultValue,
		Directives:   directives,
		Loc:          loc(parser, start),
	}), nil
}