1 // tawesoft.co.uk/go/lxstrconv 2 // 3 // Copyright © 2020 Tawesoft Ltd <open-source@tawesoft.co.uk> 4 // Copyright © 2020 Ben Golightly <ben@tawesoft.co.uk> 5 // 6 // Permission is hereby granted, free of charge, to any person obtaining a copy 7 // of this software and associated documentation files (the "Software"), to deal 8 // in the Software without restriction, including without limitation the rights 9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 // copies of the Software, and to permit persons to whom the Software is 11 // furnished to do so. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 // SOFTWARE. 20 21 // Package lxstrconv is an attempt at implementing locale-aware parsing of 22 // numbers that integrates with golang.org/x/text. 23 // 24 // If golang.org/x/text is ever promoted to core then there will be a new version 25 // of this package named `lstrconv` (dropping the 'x'). 26 // 27 // Package Stability 28 // 29 // THIS IS A PREVIEW RELEASE, SUBJECT TO BREAKING CHANGES. 30 // 31 // Todo: 32 // 33 // * checks for integer overflow 34 // 35 // * different representations of negative numbers e.g. `(123)` vs `-123` 36 // 37 // * In cases where AcceptInteger/AcceptFloat reach a syntax error, they 38 // currently underestimate how many bytes they successfully parsed when 39 // the byte length of the string is not equal to the number of Unicode 40 // code points in the string. 41 // 42 // Example 43 // 44 // This example demonstrates British, Dutch, and Arabic locale number parsing. 45 // 46 // package main 47 // 48 // import ( 49 // "fmt" 50 // "golang.org/x/text/language" 51 // "tawesoft.co.uk/go/lxstrconv" 52 // ) 53 // 54 // func checked(f float64, e error) float64 { 55 // if e != nil { 56 // panic(e) 57 // } 58 // return f 59 // } 60 // 61 // func main() { 62 // dutch := lxstrconv.NewDecimalFormat(language.Dutch) 63 // british := lxstrconv.NewDecimalFormat(language.BritishEnglish) 64 // arabic := lxstrconv.NewDecimalFormat(language.Arabic) 65 // 66 // fmt.Printf("%f\n", checked(british.ParseFloat("1,234.56"))) 67 // fmt.Printf("%f\n", checked(dutch.ParseFloat("1.234,56"))) 68 // fmt.Printf("%f\n", checked(arabic.ParseFloat("١٬٢٣٤٫٥٦"))) 69 // } 70 // 71 // Example 72 // 73 // You can give end-users examples of the input you expect for a given locale 74 // using the /x/text package: 75 // 76 // package main 77 // 78 // import ( 79 // "golang.org/x/text/language" 80 // "golang.org/x/text/message" 81 // "golang.org/x/text/number" 82 // ) 83 // 84 // func main() { 85 // 86 // message.NewPrinter(language.English).Println(number.Decimal(123456789)) 87 // // Prints 123,456,789 88 // 89 // message.NewPrinter(language.Dutch).Println(number.Decimal(123456789)) 90 // // Prints 123.456.789 91 // 92 // message.NewPrinter(language.Malayalam).Println(number.Decimal(123456789)) 93 // // Prints 12,34,56,789 94 // 95 // message.NewPrinter(language.Bengali).Println(number.Decimal(123456789)) 96 // // Prints ১২,৩৪,৫৬,৭৮৯ 97 // } 98 // 99 // Package Information 100 // 101 // License: MIT (see LICENSE.txt) 102 // 103 // Stable: no 104 // 105 // For more information, documentation, source code, examples, support, links, 106 // etc. please see https://www.tawesoft.co.uk/go and 107 // https://www.tawesoft.co.uk/go/lxstrconv 108 package lxstrconv // import "tawesoft.co.uk/go/lxstrconv" 109 110 // Code generated by internal. DO NOT EDIT. 111 // Instead, edit DESC.txt and run mkdocs.sh.