UNPKG

1.8 kBtext/coffeescriptView Raw
1
2# The C library function int isspace(int c) checks
3# whether the passed character is white-space.
4
5strcmp = (str1, str2) ->
6 # http://kevin.vanzonneveld.net
7 # + original by: Waldo Malqui Silva
8 # + input by: Steve Hilder
9 # + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
10 # + revised by: gorthaur
11 # * example 1: strcmp( 'waldo', 'owald' )
12 # * returns 1: 1
13 # * example 2: strcmp( 'owald', 'waldo' )
14 # * returns 2: -1
15 if str1 == str2 then 0 else if str1 > str2 then 1 else -1
16
17
18doubleToReasonableString = (d) ->
19
20 # when generating code, print out
21 # with the maximum possible precision
22 if codeGen
23 return d + ""
24
25 # remove trailing zeroes beyond decimal point and
26 # gives at most 6 digits after the point
27 stringRepresentation = "" + parseFloat(d.toPrecision(6))
28
29 # we actually want to give a hint to user that
30 # it's a double, so add a trailing ".0" if there
31 # is no decimal point
32 if stringRepresentation.indexOf(".") == -1
33 stringRepresentation += ".0"
34
35 return stringRepresentation
36
37# does nothing
38clear_term = ->
39
40# s is a string here anyways
41isspace = (s) ->
42 if !s? then return false
43 return s == ' ' or s == '\t' or s == '\n' or s == '\v' or s == '\f' or s == '\r'
44
45isdigit = (str) ->
46 if !str? then return false
47 return /^\d+$/.test(str)
48
49isalpha = (str) ->
50 if !str? then return false
51 #Check for non-alphabetic characters and space
52 return (str.search(/[^A-Za-z]/) == -1)
53
54isalphaOrUnderscore = (str) ->
55 if !str? then return false
56 #Check for non-alphabetic characters and space
57 return (str.search(/[^A-Za-z_]/) == -1)
58
59isunderscore = (str) ->
60 if !str? then return false
61 return (str.search(/_/) == -1)
62
63isalnumorunderscore = (str) ->
64 if !str? then return false
65 return (isalphaOrUnderscore(str) or isdigit(str))