idna 0.1 → 0.1.1
raw patch · 3 files changed
+46/−28 lines, 3 files
Files
- LICENSE +30/−24
- Text/IDNA.hs +14/−2
- idna.cabal +2/−2
LICENSE view
@@ -1,24 +1,30 @@-* Copyright (c) 2009, George Pollard-* All rights reserved.-*-* Redistribution and use in source and binary forms, with or without-* modification, are permitted provided that the following conditions are met:-* * Redistributions of source code must retain the above copyright-* notice, this list of conditions and the following disclaimer.-* * Redistributions in binary form must reproduce the above copyright-* notice, this list of conditions and the following disclaimer in the-* documentation and/or other materials provided with the distribution.-* * Neither the name of the <organization> nor the-* names of its contributors may be used to endorse or promote products-* derived from this software without specific prior written permission.-*-* THIS SOFTWARE IS PROVIDED BY <copyright holder> ''AS IS'' AND ANY-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE-* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+Copyright (c) 2009 George Pollard++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions+are met:++1. Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++2. Redistributions in binary form must reproduce the above copyright+ notice, this list of conditions and the following disclaimer in the+ documentation and/or other materials provided with the distribution.++3. Neither the name of the author nor the names of his contributors+ may be used to endorse or promote products derived from this software+ without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE+POSSIBILITY OF SUCH DAMAGE.
Text/IDNA.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE OverloadedStrings #-}+-- | This module implements the two algorithms from RFC 3490. (<http://tools.ietf.org/html/rfc3490>) module Text.IDNA (acePrefix, toASCII, toUnicode) where @@ -9,11 +10,18 @@ import Data.Encoding.ByteSink import Data.Encoding import qualified Data.Text as Text+import Data.Text (Text) import qualified Data.Text.Encoding as E -acePrefix :: Text.Text+-- | The ASCII Compatible Encoding prefix (currently \'@xn--@\').+acePrefix :: Text acePrefix = "xn--" +-- | Implements the ToASCII algorithm.+toASCII :: Bool -- ^ Whether to allow unassigned code points (in RFC: AllowUnassigned).+ -> Bool -- ^ Whether to disallow certain ASCII characters (in RFC: UseSTD3ASCIIRules). + -> Text -- ^ The text to transform.+ -> Maybe Text toASCII allowUnassigned useSTD3ASCIIRules t = do step2 <- if Text.any (>'\x7f') t then runStringPrep (namePrepProfile allowUnassigned) t@@ -42,6 +50,10 @@ '\x5b' <= c && c <= '\x60' || '\x7b' <= c && c <= '\x7f' +toUnicode :: Bool -- ^ Whether to allow unassigned code points (in RFC: AllowUnassigned).+ -> Bool -- ^ Whether to disallow certain ASCII characters (in RFC: UseSTD3ASCIIRules). + -> Text -- ^ The text to transform.+ -> Text toUnicode allowUnassigned useSTD3ASCIIRules t = mergeEither $ do step2 <- if Text.any (>'\x7f') t then case runStringPrep (namePrepProfile allowUnassigned) t of@@ -73,5 +85,5 @@ Left x >>= _ = Left x Right y >>= f = f y -tests :: [Text.Text]+tests :: [Text] tests = ["Bücher","tūdaliņ"]
idna.cabal view
@@ -1,5 +1,5 @@ Name: idna-Version: 0.1+Version: 0.1.1 Description: Implements IDNA -- Internationalized Domain Names in Applications (RFC 3490). Synopsis: Implements IDNA (RFC 3490). License: BSD3@@ -8,7 +8,7 @@ Build-Type: Simple Cabal-Version: >=1.6 License-file: LICENSE-Category: data text+Category: Data, Text, RFC Library Build-Depends: base, encoding>=0.5.1, stringprep>=0.1.2, text>=0.1