func (l *line) vcfFormat(contigName string, positionNum int64, position *Position) []byte { l.buffer = l.buffer[:0] // #CHROM l.buffer = append(l.buffer, contigName...) l.buffer = append(l.buffer, '\t') // POS l.buffer = strconv.AppendInt(l.buffer, int64(positionNum), 10) // ID l.buffer = append(l.buffer, '\t', '.', '\t') // REF l.buffer = append(l.buffer, position.callStr[0], '\t') // QUAL l.buffer = append(l.buffer, '\t', '.', '\t') // FILTER if position.isAllCalled && position.isAllPassCoverage && position.isAllPassProportion { l.buffer = append(l.buffer, 'P', 'A', 'S', 'S', '\t') } else { l.buffer = append(l.buffer, 'F', 'A', 'I', 'L', '\t') } // INFO l.buffer = append(l.buffer, 'A', 'N', '=') //l.buffer = strconv.AppendInt(l.buffer, len(alts), 10) l.buffer = append(l.buffer, ';', 'N', 'S', '=') l.buffer = strconv.AppendInt(l.buffer, position.calledReference+position.calledSnp, 10) // FORMAT l.buffer = append(l.buffer, '\t', 'G', 'T', ':', 'F', 'T', '\t') // sample analysis columns //l.vcfSampleAnalysisColumns(position.pattern, position.callWasMade, position.passedDepthFilter, position.passedProportionFilter) return l.buffer }
// FmtTimeMedium returns the medium time representation of 't' for 'en_SC' func (en *en_SC) FmtTimeMedium(t time.Time) string { b := make([]byte, 0, 32) if t.Hour() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Hour()), 10) b = append(b, en.timeSeparator...) if t.Minute() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Minute()), 10) b = append(b, en.timeSeparator...) if t.Second() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Second()), 10) return string(b) }
// FmtTimeFull returns the full time representation of 't' for 'en_SC' func (en *en_SC) FmtTimeFull(t time.Time) string { b := make([]byte, 0, 32) if t.Hour() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Hour()), 10) b = append(b, en.timeSeparator...) if t.Minute() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Minute()), 10) b = append(b, en.timeSeparator...) if t.Second() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Second()), 10) b = append(b, []byte{0x20}...) tz, _ := t.Zone() if btz, ok := en.timezones[tz]; ok { b = append(b, btz...) } else { b = append(b, tz...) } return string(b) }
// FmtTimeMedium returns the medium time representation of 't' for 'be_BY' func (be *be_BY) FmtTimeMedium(t time.Time) string { b := make([]byte, 0, 32) if t.Hour() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Hour()), 10) b = append(b, []byte{0x2e}...) if t.Minute() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Minute()), 10) b = append(b, []byte{0x2e}...) if t.Second() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Second()), 10) return string(b) }
func formatTextValue(value interface{}) ([]byte, error) { switch v := value.(type) { case int8: return strconv.AppendInt(nil, int64(v), 10), nil case int16: return strconv.AppendInt(nil, int64(v), 10), nil case int32: return strconv.AppendInt(nil, int64(v), 10), nil case int64: return strconv.AppendInt(nil, int64(v), 10), nil case int: return strconv.AppendInt(nil, int64(v), 10), nil case uint8: return strconv.AppendUint(nil, uint64(v), 10), nil case uint16: return strconv.AppendUint(nil, uint64(v), 10), nil case uint32: return strconv.AppendUint(nil, uint64(v), 10), nil case uint64: return strconv.AppendUint(nil, uint64(v), 10), nil case uint: return strconv.AppendUint(nil, uint64(v), 10), nil case float32: return strconv.AppendFloat(nil, float64(v), 'f', -1, 64), nil case float64: return strconv.AppendFloat(nil, float64(v), 'f', -1, 64), nil case []byte: return v, nil case string: return hack.Slice(v), nil default: return nil, errors.Errorf("invalid type %T", value) } }
func MarshalRaw(results []*MetricData) []byte { var b []byte for _, r := range results { b = append(b, r.GetName()...) b = append(b, ',') b = strconv.AppendInt(b, int64(r.GetStartTime()), 10) b = append(b, ',') b = strconv.AppendInt(b, int64(r.GetStopTime()), 10) b = append(b, ',') b = strconv.AppendInt(b, int64(r.GetStepTime()), 10) b = append(b, '|') var comma bool for i, v := range r.Values { if comma { b = append(b, ',') } comma = true if r.IsAbsent[i] { b = append(b, "None"...) } else { b = strconv.AppendFloat(b, v, 'f', -1, 64) } } b = append(b, '\n') } return b }
// FmtTimeShort returns the short time representation of 't' for 'ta_MY' func (ta *ta_MY) FmtTimeShort(t time.Time) string { b := make([]byte, 0, 32) if t.Hour() < 12 { b = append(b, ta.periodsAbbreviated[0]...) } else { b = append(b, ta.periodsAbbreviated[1]...) } b = append(b, []byte{0x20}...) h := t.Hour() if h > 12 { h -= 12 } b = strconv.AppendInt(b, int64(h), 10) b = append(b, ta.timeSeparator...) if t.Minute() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Minute()), 10) return string(b) }
// NewSyntaxError returns a SyntaxError wrapping around json.SyntaxError. // The provided jsonContents should be the input that produced the error // the contextSize is the number of lines around the to be printed as well // // Notice: in the message all the tabs are replaced by a single space func NewSyntaxError(original *json.SyntaxError, jsonContents []byte, contextSize int64) *SyntaxError { if len(jsonContents) == 0 { return &SyntaxError{ original: original, // replace the tabs so that the offset is correct msg: strings.Join( []string{"with no json contents got :", original.Error()}, ""), } } context, offsetOnLine, nextLineOffset := getContextAroundOffset(jsonContents, original.Offset, contextSize) var errorShowingLineBuffer = make([][]byte, 0, 9) errorShowingLineBuffer = append(errorShowingLineBuffer, replaceTabsWithSpace(context[:nextLineOffset])) errorShowingLineBuffer = append(errorShowingLineBuffer, []byte{newline}) if offsetOnLine > 2 { errorShowingLineBuffer = append(errorShowingLineBuffer, bytes.Repeat([]byte{'-'}, int(offsetOnLine-2))) } var lineNumber = bytes.Count(jsonContents[:original.Offset], []byte{newline}) + 1 errorShowingLineBuffer = append(errorShowingLineBuffer, strconv.AppendInt([]byte("^ on line "), int64(lineNumber), 10)) errorShowingLineBuffer = append(errorShowingLineBuffer, strconv.AppendInt([]byte(" column "), offsetOnLine, 10)) errorShowingLineBuffer = append(errorShowingLineBuffer, []byte(" got :")) errorShowingLineBuffer = append(errorShowingLineBuffer, []byte(original.Error())) errorShowingLineBuffer = append(errorShowingLineBuffer, replaceTabsWithSpace(context[nextLineOffset:])) var msg = bytes.Join(errorShowingLineBuffer, []byte{}) return &SyntaxError{ original: original, // replace the tabs so that the offset is correct msg: string(msg), } }
func encodeDefault(object interface{}) (buffer []byte, err error) { switch object.(type) { case bool: buffer = strconv.AppendBool(buffer, object.(bool)) case int: buffer = strconv.AppendInt(buffer, int64(object.(int)), _NUMERIC_BASE) case int8: buffer = strconv.AppendInt(buffer, int64(object.(int8)), _NUMERIC_BASE) case int16: buffer = strconv.AppendInt(buffer, int64(object.(int16)), _NUMERIC_BASE) case int32: buffer = strconv.AppendInt(buffer, int64(object.(int32)), _NUMERIC_BASE) case int64: buffer = strconv.AppendInt(buffer, object.(int64), _NUMERIC_BASE) case uint: buffer = strconv.AppendUint(buffer, uint64(object.(uint)), _NUMERIC_BASE) case uint8: buffer = strconv.AppendUint(buffer, uint64(object.(uint8)), _NUMERIC_BASE) case uint16: buffer = strconv.AppendUint(buffer, uint64(object.(uint16)), _NUMERIC_BASE) case uint32: buffer = strconv.AppendUint(buffer, uint64(object.(uint32)), _NUMERIC_BASE) case uint64: buffer = strconv.AppendUint(buffer, object.(uint64), _NUMERIC_BASE) case string: buffer = []byte(object.(string)) case []byte: buffer = object.([]byte) default: err = errors.New("Invalid object for default encode") } return }
// FmtDateShort returns the short date representation of 't' for 'bg_BG' func (bg *bg_BG) FmtDateShort(t time.Time) string { b := make([]byte, 0, 32) b = strconv.AppendInt(b, int64(t.Day()), 10) b = append(b, []byte{0x2e}...) if t.Month() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Month()), 10) b = append(b, []byte{0x2e}...) if t.Year() > 9 { b = append(b, strconv.Itoa(t.Year())[2:]...) } else { b = append(b, strconv.Itoa(t.Year())[1:]...) } b = append(b, []byte{0x20, 0xd0, 0xb3}...) b = append(b, []byte{0x2e}...) return string(b) }
// FmtTimeLong returns the long time representation of 't' for 'uz_Latn_UZ' func (uz *uz_Latn_UZ) FmtTimeLong(t time.Time) string { b := make([]byte, 0, 32) b = strconv.AppendInt(b, int64(t.Hour()), 10) b = append(b, uz.timeSeparator...) if t.Minute() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Minute()), 10) b = append(b, uz.timeSeparator...) if t.Second() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Second()), 10) b = append(b, []byte{0x20, 0x28}...) tz, _ := t.Zone() b = append(b, tz...) b = append(b, []byte{0x29}...) return string(b) }
// FmtTimeMedium returns the medium time representation of 't' for 'zh_Hans_MO' func (zh *zh_Hans_MO) FmtTimeMedium(t time.Time) string { b := make([]byte, 0, 32) if t.Hour() < 12 { b = append(b, zh.periodsAbbreviated[0]...) } else { b = append(b, zh.periodsAbbreviated[1]...) } h := t.Hour() if h > 12 { h -= 12 } b = strconv.AppendInt(b, int64(h), 10) b = append(b, zh.timeSeparator...) if t.Minute() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Minute()), 10) b = append(b, zh.timeSeparator...) if t.Second() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Second()), 10) return string(b) }
// FmtTimeFull returns the full time representation of 't' for 'fr_BE' func (fr *fr_BE) FmtTimeFull(t time.Time) string { b := make([]byte, 0, 32) b = strconv.AppendInt(b, int64(t.Hour()), 10) b = append(b, []byte{0x20, 0x68}...) b = append(b, []byte{0x20}...) if t.Minute() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Minute()), 10) b = append(b, []byte{0x20, 0x6d, 0x69, 0x6e}...) b = append(b, []byte{0x20}...) if t.Second() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Second()), 10) b = append(b, []byte{0x20, 0x73}...) b = append(b, []byte{0x20}...) tz, _ := t.Zone() if btz, ok := fr.timezones[tz]; ok { b = append(b, btz...) } else { b = append(b, tz...) } return string(b) }
// FmtDateLong returns the long date representation of 't' for 'vi_VN' func (vi *vi_VN) FmtDateLong(t time.Time) string { b := make([]byte, 0, 32) b = append(b, []byte{0x4e, 0x67, 0xc3, 0xa0, 0x79}...) b = append(b, []byte{0x20}...) if t.Day() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Day()), 10) b = append(b, []byte{0x20, 0x74, 0x68, 0xc3, 0xa1, 0x6e, 0x67}...) b = append(b, []byte{0x20}...) if t.Month() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Month()), 10) b = append(b, []byte{0x20, 0x6e, 0xc4, 0x83, 0x6d}...) b = append(b, []byte{0x20}...) b = strconv.AppendInt(b, int64(t.Year()), 10) return string(b) }
func appendPadded(bs []byte, i int, sz int) []byte { if i < 0 { bs = append(bs, '-') i = -i } if i < 10 { for ; sz > 1; sz-- { bs = append(bs, '0') } return append(bs, byte(i)+'0') } if i < 100 { for ; sz > 2; sz-- { bs = append(bs, '0') } return strconv.AppendInt(bs, int64(i), 10) } digits := 0 if i < 1000 { digits = 3 } else if i < 10000 { digits = 4 } else { digits = int(math.Log10(float64(i))) + 1 } for ; sz > digits; sz-- { bs = append(bs, '0') } return strconv.AppendInt(bs, int64(i), 10) }
// FmtTimeFull returns the full time representation of 't' for 'ja' func (ja *ja) FmtTimeFull(t time.Time) string { b := make([]byte, 0, 32) b = strconv.AppendInt(b, int64(t.Hour()), 10) b = append(b, []byte{0xe6, 0x99, 0x82}...) if t.Minute() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Minute()), 10) b = append(b, []byte{0xe5, 0x88, 0x86}...) if t.Second() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Second()), 10) b = append(b, []byte{0xe7, 0xa7, 0x92, 0x20}...) tz, _ := t.Zone() if btz, ok := ja.timezones[tz]; ok { b = append(b, btz...) } else { b = append(b, tz...) } return string(b) }
// FmtDateFull returns the full date representation of 't' for 'ti_ER' func (ti *ti_ER) FmtDateFull(t time.Time) string { b := make([]byte, 0, 32) b = append(b, ti.daysWide[t.Weekday()]...) b = append(b, []byte{0xe1, 0x8d, 0xa1, 0x20}...) if t.Day() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Day()), 10) b = append(b, []byte{0x20}...) b = append(b, ti.monthsWide[t.Month()]...) b = append(b, []byte{0x20, 0xe1, 0x88, 0x98, 0xe1, 0x8b, 0x93, 0xe1, 0x88, 0x8d, 0xe1, 0x89, 0xb2, 0x20}...) b = strconv.AppendInt(b, int64(t.Year()), 10) b = append(b, []byte{0x20}...) if t.Year() < 0 { b = append(b, ti.erasWide[0]...) } else { b = append(b, ti.erasWide[1]...) } return string(b) }
// FmtTimeFull returns the full time representation of 't' for 'uz_Arab_AF' func (uz *uz_Arab_AF) FmtTimeFull(t time.Time) string { b := make([]byte, 0, 32) b = strconv.AppendInt(b, int64(t.Hour()), 10) b = append(b, uz.timeSeparator...) if t.Minute() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Minute()), 10) b = append(b, uz.timeSeparator...) if t.Second() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Second()), 10) b = append(b, []byte{0x20, 0x28}...) tz, _ := t.Zone() if btz, ok := uz.timezones[tz]; ok { b = append(b, btz...) } else { b = append(b, tz...) } b = append(b, []byte{0x29}...) return string(b) }
// FmtTimeFull returns the full time representation of 't' for 'eo' func (eo *eo) FmtTimeFull(t time.Time) string { b := make([]byte, 0, 32) b = strconv.AppendInt(b, int64(t.Hour()), 10) b = append(b, []byte{0x2d, 0x61}...) b = append(b, []byte{0x20, 0x68, 0x6f, 0x72, 0x6f}...) b = append(b, []byte{0x20, 0x6b, 0x61, 0x6a}...) b = append(b, []byte{0x20}...) b = strconv.AppendInt(b, int64(t.Minute()), 10) b = append(b, eo.timeSeparator...) if t.Second() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Second()), 10) b = append(b, []byte{0x20}...) tz, _ := t.Zone() if btz, ok := eo.timezones[tz]; ok { b = append(b, btz...) } else { b = append(b, tz...) } return string(b) }
// FmtTimeShort returns the short time representation of 't' for 'as_IN' func (as *as_IN) FmtTimeShort(t time.Time) string { b := make([]byte, 0, 32) h := t.Hour() if h > 12 { h -= 12 } b = strconv.AppendInt(b, int64(h), 10) b = append(b, []byte{0x2e}...) if t.Minute() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Minute()), 10) b = append(b, []byte{0x2e, 0x20}...) if t.Hour() < 12 { b = append(b, as.periodsAbbreviated[0]...) } else { b = append(b, as.periodsAbbreviated[1]...) } return string(b) }
func BuildValue(goval interface{}) (v Value, err error) { switch bindVal := goval.(type) { case nil: // no op case int: v = Value{Numeric(strconv.AppendInt(nil, int64(bindVal), 10))} case int32: v = Value{Numeric(strconv.AppendInt(nil, int64(bindVal), 10))} case int64: v = Value{Numeric(strconv.AppendInt(nil, int64(bindVal), 10))} case uint: v = Value{Numeric(strconv.AppendUint(nil, uint64(bindVal), 10))} case uint32: v = Value{Numeric(strconv.AppendUint(nil, uint64(bindVal), 10))} case uint64: v = Value{Numeric(strconv.AppendUint(nil, uint64(bindVal), 10))} case float64: v = Value{Fractional(strconv.AppendFloat(nil, bindVal, 'f', -1, 64))} case string: v = Value{String([]byte(bindVal))} case []byte: v = Value{String(bindVal)} case time.Time: v = Value{String([]byte(bindVal.Format("'2006-01-02 15:04:05'")))} case Numeric, Fractional, String: v = Value{bindVal.(InnerValue)} case Value: v = bindVal default: return Value{}, fmt.Errorf("Unsupported bind variable type %T: %v", goval, goval) } return v, nil }
func (c *conn) writeStoreCommand(cmd, key string, value []byte, flags uint32, timeout int32, cas uint64) (err error) { if len(value) > 1000000 { return protocolError("max value size, greate than 1mb") } // <command name> <key> <flags> <exptime> <bytes> [noreply]\r\n c.bw.WriteString(cmd) c.bw.WriteByte(space) c.bw.WriteString(key) c.bw.WriteByte(space) c.bw.Write(strconv.AppendUint(c.numScratch[:0], uint64(flags), 10)) c.bw.WriteByte(space) c.bw.Write(strconv.AppendInt(c.numScratch[:0], int64(timeout), 10)) c.bw.WriteByte(space) c.bw.Write(strconv.AppendInt(c.numScratch[:0], int64(len(value)), 10)) if cas != 0 { c.bw.WriteByte(space) c.bw.Write(strconv.AppendUint(c.numScratch[:0], cas, 10)) } c.bw.Write(crlf) // <data block>\r\n c.bw.Write(value) _, err = c.bw.Write(crlf) return }
// FmtTimeMedium returns the medium time representation of 't' for 'ar_SA' func (ar *ar_SA) FmtTimeMedium(t time.Time) string { b := make([]byte, 0, 32) h := t.Hour() if h > 12 { h -= 12 } b = strconv.AppendInt(b, int64(h), 10) b = append(b, ar.timeSeparator...) if t.Minute() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Minute()), 10) b = append(b, ar.timeSeparator...) if t.Second() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Second()), 10) b = append(b, []byte{0x20}...) if t.Hour() < 12 { b = append(b, ar.periodsAbbreviated[0]...) } else { b = append(b, ar.periodsAbbreviated[1]...) } return string(b) }
// FmtTimeShort returns the short time representation of 't' for 'dz_BT' func (dz *dz_BT) FmtTimeShort(t time.Time) string { b := make([]byte, 0, 32) b = append(b, []byte{0xe0, 0xbd, 0x86, 0xe0, 0xbd, 0xb4, 0xe0, 0xbc, 0x8b, 0xe0, 0xbd, 0x9a, 0xe0, 0xbd, 0xbc, 0xe0, 0xbd, 0x91, 0xe0, 0xbc, 0x8b, 0x20}...) h := t.Hour() if h > 12 { h -= 12 } b = strconv.AppendInt(b, int64(h), 10) b = append(b, []byte{0x20, 0xe0, 0xbd, 0xa6, 0xe0, 0xbe, 0x90, 0xe0, 0xbd, 0xa2, 0xe0, 0xbc, 0x8b, 0xe0, 0xbd, 0x98, 0xe0, 0xbc, 0x8b, 0x20}...) if t.Minute() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Minute()), 10) b = append(b, []byte{0x20}...) if t.Hour() < 12 { b = append(b, dz.periodsAbbreviated[0]...) } else { b = append(b, dz.periodsAbbreviated[1]...) } return string(b) }
// FmtDateShort returns the short date representation of 't' for 'it_IT' func (it *it_IT) FmtDateShort(t time.Time) string { b := make([]byte, 0, 32) if t.Day() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Day()), 10) b = append(b, []byte{0x2f}...) if t.Month() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Month()), 10) b = append(b, []byte{0x2f}...) if t.Year() > 9 { b = append(b, strconv.Itoa(t.Year())[2:]...) } else { b = append(b, strconv.Itoa(t.Year())[1:]...) } return string(b) }
// httpEtag returns the package entity tag used in HTTP transactions. func httpEtag(pdoc *doc.Package, pkgs []database.Package, importerCount int, flashMessages []flashMessage) string { b := make([]byte, 0, 128) b = strconv.AppendInt(b, pdoc.Updated.Unix(), 16) b = append(b, 0) b = append(b, pdoc.Etag...) if importerCount >= 8 { importerCount = 8 } b = append(b, 0) b = strconv.AppendInt(b, int64(importerCount), 16) for _, pkg := range pkgs { b = append(b, 0) b = append(b, pkg.Path...) b = append(b, 0) b = append(b, pkg.Synopsis...) } if *sidebarEnabled { b = append(b, "\000xsb"...) } for _, m := range flashMessages { b = append(b, 0) b = append(b, m.ID...) for _, a := range m.Args { b = append(b, 1) b = append(b, a...) } } h := md5.New() h.Write(b) b = h.Sum(b[:0]) return fmt.Sprintf("\"%x\"", b) }
// FmtTimeLong returns the long time representation of 't' for 'en_SC' func (en *en_SC) FmtTimeLong(t time.Time) string { b := make([]byte, 0, 32) if t.Hour() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Hour()), 10) b = append(b, en.timeSeparator...) if t.Minute() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Minute()), 10) b = append(b, en.timeSeparator...) if t.Second() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Second()), 10) b = append(b, []byte{0x20}...) tz, _ := t.Zone() b = append(b, tz...) return string(b) }
// FmtTimeLong returns the long time representation of 't' for 'sr_Cyrl_RS' func (sr *sr_Cyrl_RS) FmtTimeLong(t time.Time) string { b := make([]byte, 0, 32) if t.Hour() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Hour()), 10) b = append(b, []byte{0x2e}...) if t.Minute() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Minute()), 10) b = append(b, []byte{0x2e}...) if t.Second() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Second()), 10) b = append(b, []byte{0x20}...) tz, _ := t.Zone() b = append(b, tz...) return string(b) }
func bruteForce(obj []byte, winner chan<- solution, possibilities <-chan try) { // blob is the blob to mutate in-place repatedly while testing // whether we have a match. blob := []byte(fmt.Sprintf("commit %d\x00%s", len(obj), obj)) authorDate, adatei := getDate(blob, authorDateRx) commitDate, cdatei := getDate(blob, commiterDateRx) s1 := sha1.New() wantHexPrefix := []byte(*prefix) hexBuf := make([]byte, 0, sha1.Size*2) for t := range possibilities { ad := date{startUnix - int64(t.authorBehind), authorDate.tz} cd := date{startUnix - int64(t.commitBehind), commitDate.tz} strconv.AppendInt(blob[:adatei], ad.n, 10) strconv.AppendInt(blob[:cdatei], cd.n, 10) s1.Reset() s1.Write(blob) if !bytes.HasPrefix(hexInPlace(s1.Sum(hexBuf[:0])), wantHexPrefix) { continue } winner <- solution{ad, cd} return // at least yield one goroutine's CPU for git commit to run. } }
// FmtTimeFull returns the full time representation of 't' for 'th_TH' func (th *th_TH) FmtTimeFull(t time.Time) string { b := make([]byte, 0, 32) b = strconv.AppendInt(b, int64(t.Hour()), 10) b = append(b, []byte{0x20, 0xe0, 0xb8, 0x99, 0xe0, 0xb8, 0xb2, 0xe0, 0xb8, 0xac, 0xe0, 0xb8, 0xb4, 0xe0, 0xb8, 0x81, 0xe0, 0xb8, 0xb2, 0x20}...) if t.Minute() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Minute()), 10) b = append(b, []byte{0x20, 0xe0, 0xb8, 0x99, 0xe0, 0xb8, 0xb2, 0xe0, 0xb8, 0x97, 0xe0, 0xb8, 0xb5, 0x20}...) if t.Second() < 10 { b = append(b, '0') } b = strconv.AppendInt(b, int64(t.Second()), 10) b = append(b, []byte{0x20, 0xe0, 0xb8, 0xa7, 0xe0, 0xb8, 0xb4, 0xe0, 0xb8, 0x99, 0xe0, 0xb8, 0xb2, 0xe0, 0xb8, 0x97, 0xe0, 0xb8, 0xb5, 0x20}...) tz, _ := t.Zone() if btz, ok := th.timezones[tz]; ok { b = append(b, btz...) } else { b = append(b, tz...) } return string(b) }