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 // Todo: 28 // 29 // * checks for integer overflow 30 // 31 // * different representations of negative numbers e.g. `(123)` vs `-123` 32 // 33 // * In cases where AcceptInteger/AcceptFloat reach a syntax error, they 34 // currently underestimate how many bytes they successfully parsed when 35 // the byte length of the string is not equal to the number of Unicode 36 // code points in the string. 37 // 38 // Example 39 // 40 // This example demonstrates British, Dutch, and Arabic locale number parsing. 41 // 42 // package main 43 // 44 // import ( 45 // "fmt" 46 // "golang.org/x/text/language" 47 // "tawesoft.co.uk/go/lxstrconv" 48 // ) 49 // 50 // func checked(f float64, e error) float64 { 51 // if e != nil { 52 // panic(e) 53 // } 54 // return f 55 // } 56 // 57 // func main() { 58 // dutch := lxstrconv.NewDecimalFormat(language.Dutch) 59 // british := lxstrconv.NewDecimalFormat(language.BritishEnglish) 60 // arabic := lxstrconv.NewDecimalFormat(language.Arabic) 61 // 62 // fmt.Printf("%f\n", checked(british.ParseFloat("1,234.56"))) 63 // fmt.Printf("%f\n", checked(dutch.ParseFloat("1.234,56"))) 64 // fmt.Printf("%f\n", checked(arabic.ParseFloat("١٬٢٣٤٫٥٦"))) 65 // } 66 // 67 // Example 68 // 69 // You can give end-users examples of the input you expect for a given locale 70 // using the /x/text package: 71 // 72 // package main 73 // 74 // import ( 75 // "golang.org/x/text/language" 76 // "golang.org/x/text/message" 77 // "golang.org/x/text/number" 78 // ) 79 // 80 // func main() { 81 // 82 // message.NewPrinter(language.English).Println(number.Decimal(123456789)) 83 // // Prints 123,456,789 84 // 85 // message.NewPrinter(language.Dutch).Println(number.Decimal(123456789)) 86 // // Prints 123.456.789 87 // 88 // message.NewPrinter(language.Malayalam).Println(number.Decimal(123456789)) 89 // // Prints 12,34,56,789 90 // 91 // message.NewPrinter(language.Bengali).Println(number.Decimal(123456789)) 92 // // Prints ১২,৩৪,৫৬,৭৮৯ 93 // } 94 // 95 // FROZEN - PLEASE MIGRATE 96 // 97 // These packages are moving to https://github.com/tawesoft/golib. 98 // 99 // This is to increase security against possible supply chain attacks such as 100 // our domain name expiring in the future and being registered by someone else. 101 // 102 // Please migrate to https://github.com/tawesoft/golib (when available) instead. 103 // 104 // Most programs relying on a package in this monorepo, such as the dialog or 105 // lxstrconv packages, will continue to work for the foreseeable future. 106 // 107 // Rarely used packages have been hidden for now - they are in the git commit 108 // history at https://github.com/tawesoft/go if you need to resurrect one. 109 // 110 // 111 // Package Information 112 // 113 // License: MIT (see LICENSE.txt) 114 // 115 // Stable: yes 116 // 117 // For more information, documentation, source code, examples, support, links, 118 // etc. please see https://www.tawesoft.co.uk/go and 119 // https://www.tawesoft.co.uk/go/lxstrconv 120 package lxstrconv // import "tawesoft.co.uk/go/lxstrconv" 121 122 // Code generated by internal. DO NOT EDIT. 123 // Instead, edit DESC.txt and run mkdocs.sh.