File: Shared.hs

package info (click to toggle)
haskell-punycode 2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 76 kB
  • sloc: haskell: 348; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 763 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module Data.Text.Punycode.Shared where

import Data.Char (ord)

base :: Int
base = 36

tmin :: Int
tmin = 1

tmax :: Int
tmax = 26

skew :: Int
skew = 38

damp :: Int
damp = 700

initial_bias :: Int
initial_bias = 72

initial_n :: Int
initial_n = 128

adapt :: Int -> Int -> Bool -> Int
adapt delta numpoints firsttime = helper
  where helper = loop 0 $ delta' + (delta' `div` numpoints)
          where delta'
                  | firsttime = delta `div` damp
                  | otherwise = delta `div` 2
        loop k delta'
          | delta' > ((base - tmin) * tmax) `div` 2 = loop (k + base) $ delta' `div` (base - tmin)
          | otherwise = k + (((base - tmin + 1) * delta') `div` (delta' + skew))

isBasic :: Char -> Bool
isBasic = (< initial_n) . ord