1/** 2 * Copyright 2014 Paul Querna 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 18/* Portions of this file are on Go stdlib's strconv/iota.go */ 19// Copyright 2009 The Go Authors. All rights reserved. 20// Use of this source code is governed by a BSD-style 21// license that can be found in the LICENSE file. 22 23package v1 24 25import ( 26 "github.com/pquerna/ffjson/fflib/v1/internal" 27) 28 29func ParseFloat(s []byte, bitSize int) (f float64, err error) { 30 return internal.ParseFloat(s, bitSize) 31} 32 33// ParseUint is like ParseInt but for unsigned numbers, and oeprating on []byte 34func ParseUint(s []byte, base int, bitSize int) (n uint64, err error) { 35 if len(s) == 1 { 36 switch s[0] { 37 case '0': 38 return 0, nil 39 case '1': 40 return 1, nil 41 case '2': 42 return 2, nil 43 case '3': 44 return 3, nil 45 case '4': 46 return 4, nil 47 case '5': 48 return 5, nil 49 case '6': 50 return 6, nil 51 case '7': 52 return 7, nil 53 case '8': 54 return 8, nil 55 case '9': 56 return 9, nil 57 } 58 } 59 return internal.ParseUint(s, base, bitSize) 60} 61 62func ParseInt(s []byte, base int, bitSize int) (i int64, err error) { 63 if len(s) == 1 { 64 switch s[0] { 65 case '0': 66 return 0, nil 67 case '1': 68 return 1, nil 69 case '2': 70 return 2, nil 71 case '3': 72 return 3, nil 73 case '4': 74 return 4, nil 75 case '5': 76 return 5, nil 77 case '6': 78 return 6, nil 79 case '7': 80 return 7, nil 81 case '8': 82 return 8, nil 83 case '9': 84 return 9, nil 85 } 86 } 87 return internal.ParseInt(s, base, bitSize) 88} 89