// Raw gets the raw contents of first file in a specific gist
//
// https://developer.github.com/v3/gists/#truncation
19421
func (g *GistsService) Raw(uri *Hyperlink, uriParams M) (body io.ReadCloser, result *Result) {
	var rawURL *url.URL

	gist, result := g.One(uri, uriParams)
	for _, file := range gist.Files {
		rawURL, _ = url.Parse(file.RawURL)
		break
	}

	body, result = g.client.getBody(rawURL, textMediaType)
	return
}
1082871
func (tb *LTable) RawGet(key LValue) LValue {
	switch v := key.(type) {
	case LNumber:
		if isArrayKey(v) {
			if tb.array == nil {
				return LNil
			}
			index := int(v) - 1
			if index >= len(tb.array) {
				return LNil
			}
			return tb.array[index]
		}
	case LString:
		if tb.strdict == nil {
			return LNil
		}
		if ret, ok := tb.strdict[string(v)]; ok {
			return ret
		}
		return LNil
	}
	if tb.dict == nil {
		return LNil
	}
	if v, ok := tb.dict[key]; ok {
		return v
	}
	return LNil
}
1265249
func LoadRawData(raw interface{}) (f Float64Data) {
	var r []interface{}
	var s Float64Data

	switch t := raw.(type) {
	case []interface{}:
		r = t
	case []uint:
		for _, v := range t {
			s = append(s, float64(v))
		}
		return s
	case []uint8:
		for _, v := range t {
			s = append(s, float64(v))
		}
		return s
	case []uint16:
		for _, v := range t {
			s = append(s, float64(v))
		}
		return s
	case []uint32:
		for _, v := range t {
			s = append(s, float64(v))
		}
		return s
	case []uint64:
		for _, v := range t {
			s = append(s, float64(v))
		}
		return s
	case []bool:
		for _, v := range t {
			if v {
				s = append(s, 1.0)
			} else {
				s = append(s, 0.0)
			}
		}
		return s
	case []float64:
		return Float64Data(t)
	case []int:
		for _, v := range t {
			s = append(s, float64(v))
		}
		return s
	case []int8:
		for _, v := range t {
			s = append(s, float64(v))
		}
		return s
	case []int16:
		for _, v := range t {
			s = append(s, float64(v))
		}
		return s
	case []int32:
		for _, v := range t {
			s = append(s, float64(v))
		}
		return s
	case []int64:
		for _, v := range t {
			s = append(s, float64(v))
		}
		return s
	case []string:
		for _, v := range t {
			r = append(r, v)
		}
	case []time.Duration:
		for _, v := range t {
			r = append(r, v)
		}
	case map[int]int:
		for i := 0; i < len(t); i++ {
			s = append(s, float64(t[i]))
		}
		return s
	case map[int]int8:
		for i := 0; i < len(t); i++ {
			s = append(s, float64(t[i]))
		}
		return s
	case map[int]int16:
		for i := 0; i < len(t); i++ {
			s = append(s, float64(t[i]))
		}
		return s
	case map[int]int32:
		for i := 0; i < len(t); i++ {
			s = append(s, float64(t[i]))
		}
		return s
	case map[int]int64:
		for i := 0; i < len(t); i++ {
			s = append(s, float64(t[i]))
		}
		return s
	case map[int]string:
		for i := 0; i < len(t); i++ {
			r = append(r, t[i])
		}
	case map[int]uint:
		for i := 0; i < len(t); i++ {
			s = append(s, float64(t[i]))
		}
		return s
	case map[int]uint8:
		for i := 0; i < len(t); i++ {
			s = append(s, float64(t[i]))
		}
		return s
	case map[int]uint16:
		for i := 0; i < len(t); i++ {
			s = append(s, float64(t[i]))
		}
		return s
	case map[int]uint32:
		for i := 0; i < len(t); i++ {
			s = append(s, float64(t[i]))
		}
		return s
	case map[int]uint64:
		for i := 0; i < len(t); i++ {
			s = append(s, float64(t[i]))
		}
		return s
	case map[int]bool:
		for i := 0; i < len(t); i++ {
			if t[i] {
				s = append(s, 1.0)
			} else {
				s = append(s, 0.0)
			}
		}
		return s
	case map[int]float64:
		for i := 0; i < len(t); i++ {
			s = append(s, t[i])
		}
		return s
	case map[int]time.Duration:
		for i := 0; i < len(t); i++ {
			r = append(r, t[i])
		}
	}

	for _, v := range r {
		switch t := v.(type) {
		case int:
			a := float64(t)
			f = append(f, a)
		case uint:
			f = append(f, float64(t))
		case float64:
			f = append(f, t)
		case string:
			fl, err := strconv.ParseFloat(t, 64)
			if err == nil {
				f = append(f, fl)
			}
		case bool:
			if t {
				f = append(f, 1.0)
			} else {
				f = append(f, 0.0)
			}
		case time.Duration:
			f = append(f, float64(t))
		}
	}
	return f
}
92163
func (tb *LTable) RawGetString(key string) LValue {
	if tb.strdict == nil {
		return LNil
	}
	if v, vok := tb.strdict[string(key)]; vok {
		return v
	}
	return LNil
}
1306498
func RawPath(in string) (string, error) {
	u, err := url.ParseRequestURI(in)
	if err != nil {
		return "", err
	}
	path := ""
	if u.Opaque != "" {
		path = u.Opaque
	} else if u.Host == "" {
		path = in
	} else {
		vals := strings.SplitN(in, u.Host, 2)
		if len(vals) != 2 {
			return "", fmt.Errorf("failed to parse url")
		}
		path = vals[1]
	}
	idx := strings.IndexRune(path, '?')
	if idx == -1 {
		return path, nil
	}
	return path[:idx], nil
}
998690
func getBytes(raw string) []byte {
	rawSlice := strings.FieldsFunc(raw, isArray)
	result := make([]byte, len(rawSlice))

	i := 0
	for _, b := range rawSlice {
		fmt.Sscan(b, &result[i])
		i++
	}
	return result
}
578714
func (c *cursor) rawValue() []byte {
	// Nothing to return if cursor is exhausted.
	if c.currentIter == nil {
		return nil
	}

	return copySlice(c.currentIter.Value())
}
209720
func (d *Decoder) Decode(raw interface{}) error {
	return d.decode("", raw, reflect.ValueOf(d.config.Result).Elem())
}
1240564
func (i *UI) rawRead(f *os.File) (string, error) {

	// In windows, Handle can be used to examine or modify the system resource.
	// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724457(v=vs.85).aspx
	handle := syscall.Handle(f.Fd())

	resetFunc, err := makeRaw(handle)
	if err != nil {
		return "", err
	}
	defer resetFunc()

	return i.rawReadline(f)
}
549811
func (d DotSql) Raw(name string) (string, error) {
	return d.lookupQuery(name)
}
440517
func (w *wrapper) RawCopy() Configuration {
	w.mut.Lock()
	defer w.mut.Unlock()
	return w.cfg.Copy()
}
310298
func (c *Client) RawRequest(r *Request) (*Response, error) {
	return c.RawRequestWithContext(context.Background(), r)
}
689469
func (s *Stream) Raw() ([]byte, error) {
	kind, size, err := s.Kind()
	if err != nil {
		return nil, err
	}
	if kind == Byte {
		s.kind = -1 // rearm Kind
		return []byte{s.byteval}, nil
	}
	// the original header has already been read and is no longer
	// available. read content and put a new header in front of it.
	start := headsize(size)
	buf := make([]byte, uint64(start)+size)
	if err := s.readFull(buf[start:]); err != nil {
		return nil, err
	}
	if kind == String {
		puthead(buf, 0x80, 0xB7, size)
	} else {
		puthead(buf, 0xC0, 0xF7, size)
	}
	return buf, nil
}
670403
func NewOrderFromRaw(raw []interface{}) (o *Order, err error) {
	if len(raw) == 12 {
		o = &Order{
			ID:         int64(f64ValOrZero(raw[0])),
			Symbol:     sValOrEmpty(raw[1]),
			Amount:     f64ValOrZero(raw[2]),
			AmountOrig: f64ValOrZero(raw[3]),
			Type:       sValOrEmpty(raw[4]),
			Status:     OrderStatus(sValOrEmpty(raw[5])),
			Price:      f64ValOrZero(raw[6]),
			PriceAvg:   f64ValOrZero(raw[7]),
			MTSUpdated: i64ValOrZero(raw[8]),
			// 3 trailing zeroes, what do they map to?
		}
	} else if len(raw) < 26 {
		return o, fmt.Errorf("data slice too short for order: %#v", raw)
	} else {
		// TODO: API docs say ID, GID, CID, MTS_CREATE, MTS_UPDATE are int but API returns float
		o = &Order{
			ID:            int64(f64ValOrZero(raw[0])),
			GID:           int64(f64ValOrZero(raw[1])),
			CID:           int64(f64ValOrZero(raw[2])),
			Symbol:        sValOrEmpty(raw[3]),
			MTSCreated:    int64(f64ValOrZero(raw[4])),
			MTSUpdated:    int64(f64ValOrZero(raw[5])),
			Amount:        f64ValOrZero(raw[6]),
			AmountOrig:    f64ValOrZero(raw[7]),
			Type:          sValOrEmpty(raw[8]),
			TypePrev:      sValOrEmpty(raw[9]),
			MTSTif:        int64(f64ValOrZero(raw[10])),
			Flags:         i64ValOrZero(raw[12]),
			Status:        OrderStatus(sValOrEmpty(raw[13])),
			Price:         f64ValOrZero(raw[16]),
			PriceAvg:      f64ValOrZero(raw[17]),
			PriceTrailing: f64ValOrZero(raw[18]),
			PriceAuxLimit: f64ValOrZero(raw[19]),
			Notify:        bValOrFalse(raw[23]),
			Hidden:        bValOrFalse(raw[24]),
			PlacedID:      i64ValOrZero(raw[25]),
		}
	}

	return
}
130821
func (d *Decoder) raw(f *codecFnInfo, rv reflect.Value) {
	rv.SetBytes(d.rawBytes())
}
206963
func (tb *LTable) RawSet(key LValue, value LValue) {
	switch v := key.(type) {
	case LNumber:
		if isArrayKey(v) {
			if tb.array == nil {
				tb.array = make([]LValue, 0, defaultArrayCap)
			}
			index := int(v) - 1
			alen := len(tb.array)
			switch {
			case index == alen:
				tb.array = append(tb.array, value)
			case index > alen:
				for i := 0; i < (index - alen); i++ {
					tb.array = append(tb.array, LNil)
				}
				tb.array = append(tb.array, value)
			case index < alen:
				tb.array[index] = value
			}
			return
		}
	case LString:
		tb.RawSetString(string(v), value)
		return
	}

	tb.RawSetH(key, value)
}
789088
func (e *Error) RawLine() (line string, available bool, outErr error) {
	if e.Line <= 0 || e.Filename == "<string>" {
		return "", false, nil
	}

	filename := e.Filename
	if e.Template != nil {
		filename = e.Template.set.resolveFilename(e.Template, e.Filename)
	}
	file, err := os.Open(filename)
	if err != nil {
		return "", false, err
	}
	defer func() {
		err := file.Close()
		if err != nil && outErr == nil {
			outErr = err
		}
	}()

	scanner := bufio.NewScanner(file)
	l := 0
	for scanner.Scan() {
		l++
		if l == e.Line {
			return scanner.Text(), true, nil
		}
	}
	return "", false, nil
}