packages feed

web-css (empty) → 0.1.0

raw patch · 4 files changed

+104/−0 lines, 4 filesdep +basedep +textsetup-changed

Dependencies added: base, text

Files

+ LICENSE.txt view
@@ -0,0 +1,30 @@+Copyright (c) Bardur Arantsson, 2011++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 Bardur Arantsson nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"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 COPYRIGHT+OWNER 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.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Web/CSS/Escaping.hs view
@@ -0,0 +1,51 @@+module Web.CSS.Escaping+       ( escapeIdentifier+       , escapeString+       ) where++import qualified Data.Text.Lazy as TL+import qualified Data.Text.Lazy.Builder as TLB+import qualified Data.Text.Lazy.Builder.Int as TLBI++-- | Format a character as a hex escape.+escapeChar :: Char -> TL.Text+escapeChar =+  TL.cons '\\' .+  TL.justifyRight 6 '0' .+  TLB.toLazyText .+  TLBI.hexadecimal .+  fromEnum++-- | Escape a CSS identifier. This function is slightly more+-- permissive than the CSS standard. For example, it does not reject+-- identifiers that begin with two hyphens. The function always+-- escapes 'special' characters such as the tilde (@~@) or left+-- bracket (@[@). As such, they will never be interpreted as special+-- characters.+escapeIdentifier :: TL.Text -> TL.Text+escapeIdentifier = TL.concatMap escape+  where+    escape c | c >= 'a' && c <= 'z' = TL.singleton c     -- No escaping+    escape c | c >= 'A' && c <= 'Z' = TL.singleton c     -- No escaping+    escape c | c >= '0' && c <= '9' = TL.singleton c     -- No escaping+    escape c @ '_' = TL.singleton c                      -- No escaping+    escape c @ '-' = TL.singleton c                      -- No escaping+    escape c | c >= ' ' && c <= '~' = TL.pack ['\\', c]  -- Simple escapes+    escape c = escapeChar c                              -- General escape++-- | Escape a CSS string value. This function is conservative and+-- produces only output characters in the US-ASCII range. This comes+-- at the cost of space usage, so this function should not be used to+-- encode strings expected to contain a disproportionate amount of+-- non-US-ASCII characters.+escapeString :: TL.Text -> TL.Text+escapeString s =+  TL.concat [ TL.pack "\""+            , TL.concatMap escape s+            , TL.pack "\""+            ]+    where+      escape c | c < ' ' = escapeChar c             -- Control characters+      escape c | c > '~' = escapeChar c             -- Outside US-ASCII.+      escape c @ '"' = TL.pack ['\\', c]            -- Quotes+      escape c = TL.singleton c                     -- Non-quote, US-ASCII.
+ web-css.cabal view
@@ -0,0 +1,21 @@+Name:                web-css+Version:             0.1.0+Synopsis:            Simple functions for CSS.+Description:         Simple functions for CSS. Currently contains only functions for escaping string values and identifiers for CSS.+License:             BSD3+License-file:        LICENSE.txt+Author:              Bardur Arantsson+Maintainer:          bardur@scientician.net+Stability:           Experimental+Category:            Web+Build-type:          Simple+Cabal-version:       >=1.6++Library++  Hs-source-dirs:  src++  Exposed-modules: Web.CSS.Escaping++  Build-depends:   base >= 4 && < 5+                 , text >= 0.11.1.0 && < 0.12