diff --git a/src/dataType/utString.erl b/src/dataType/utString.erl index a7702cd..09719a3 100644 --- a/src/dataType/utString.erl +++ b/src/dataType/utString.erl @@ -9,29 +9,51 @@ , isAlpha/1 ]). -toLowerStr(List) when is_list(List) -> - [begin - case C >= $A andalso C =< $Z of - true -> - C + 32; - _ -> - C - end - end || C <- List]; -toLowerStr(Bin) when is_binary(Bin) -> - toLowerStr(utTypeCast:toList(Bin)). - -toUpperStr(List) when is_list(List) -> - [begin - case C >= $a andalso C =< $z of - true -> - C - 32; - _ -> - C - end - end || C <- List]; -toUpperStr(Bin) when is_binary(Bin) -> - toUpperStr(utTypeCast:toList(Bin)). +toLowerStr(ListStr) when is_list(ListStr) -> + [ + begin + case C >= $A andalso C =< $Z of + true -> + C + 32; + _ -> + C + end + end || C <- ListStr + ]; +toLowerStr(BinStr) when is_binary(BinStr) -> + << + begin + case C >= $A andalso C =< $Z of + true -> + <<(C + 32)>>; + _ -> + <> + end + end || <> <= BinStr + >>. + +toUpperStr(ListStr) when is_list(ListStr) -> + [ + begin + case C >= $a andalso C =< $z of + true -> + C - 32; + _ -> + C + end + end || C <- ListStr + ]; +toUpperStr(BinStr) when is_binary(BinStr) -> + << + begin + case C >= $a andalso C =< $z of + true -> + <<(C - 32)>>; + _ -> + <> + end + end || <> <= BinStr + >>. -spec isAlpha(Char :: char()) -> boolean(). isAlpha(Char) -> @@ -47,22 +69,20 @@ isAlphaNum(Char) -> isAlpha(Char) orelse isNum(Char). %% 字符加密 -check_char_encrypt(Id, Time, TK) -> +checkEncrypt(Id, Time, TK) -> TICKET = "7YnELt8MmA4jVED7", Hex = utMd5:getMd5HexBin(lists:concat([Time, Id, TICKET])), - %NowTime = time:unixtime(), - %Hex =:= TK andalso NowTime - Time >= -10 andalso NowTime - Time < 300. - Hex =:= TK. - + NowTime = utTime:now(), + Hex =:= TK andalso NowTime - Time >= -10 andalso NowTime - Time < 300. %% Function: 检查客户端发过来的内容,false为不合法,true为合法 -%% @param: String: 客户端发来的字符串 +%% @param: String: 客户端发来的字符串 格式为binary %% @param: Length: 服务端限制的字符串长度 -check_string(String, Length) -> - case check_length(String, Length) of +checkValid(BinStr, Length) -> + case checkLen(BinStr, Length) of true -> - not check_keyword(String, ["'", "/", "\"", "_", "<", ">"]); - false -> + not checkKeyword(BinStr, ["'", "/", "\"", "_", "<", ">"]); + _ -> false end. @@ -70,21 +90,21 @@ check_string(String, Length) -> %% @spec check_keyword(Text, Words) -> false | true %% @param Text : 需要检查的字符串(或字符串的二进制形式) %% @param Words: 非法字符列表 -check_keyword(_, []) -> +checkKeyword(_, []) -> false; -check_keyword(Text, [Word | Words]) -> +checkKeyword(Text, [Word | Words]) -> case re:run(Text, Word, [{capture, none}]) of - match -> - true; nomatch -> - check_keyword(Text, Words) + checkKeyword(Text, Words); + _ -> + true end. %% 长度合法性检查 -check_length(Item, LenLimit) -> - check_length(Item, 1, LenLimit). +checkLen(BinStr, LenLimit) -> + checkLen(BinStr, 1, LenLimit). -check_length(Item, MinLen, MaxLen) -> +checkLen(BinStr, MinLen, MaxLen) -> % case asn1rt:utf8_binary_to_list(list_to_binary(Item)) of % {ok, UnicodeList} -> % Len = string_width(UnicodeList), @@ -92,7 +112,8 @@ check_length(Item, MinLen, MaxLen) -> % {error, _Reason} -> % false % end. - case unicode:characters_to_list(list_to_binary(Item)) of + % case unicode:characters_to_list(list_to_binary(BinStr)) of + case unicode:characters_to_list(BinStr) of UnicodeList when is_list(UnicodeList) -> Len = string_width(UnicodeList), Len =< MaxLen andalso Len >= MinLen; @@ -146,16 +167,16 @@ listToUtfString(List) -> %% desc 获取字符串汉字和非汉字的个数 %% parm UTF8String UTF8编码的字符串 %% return {汉字个数,非汉字个数} -getChineseNum(UTF8String) -> +getChineseCnt(UTF8String) -> UnicodeList = unicode:characters_to_list(list_to_binary(UTF8String)), - Fun = fun(Num, {Sum}) -> + Fun = fun(Num, Sum) -> case Num >= ?UNICODE_CHINESE_BEGIN andalso Num =< ?UNICODE_CHINESE_END of true -> - {Sum + 1}; + Sum + 1; false -> - {Sum} + Sum end end, - {ChineseCount} = lists:foldl(Fun, {0}, UnicodeList), + ChineseCount = lists:foldl(Fun, 0, UnicodeList), OtherCount = length(UnicodeList) - ChineseCount, {ChineseCount, OtherCount}. diff --git a/src/docs/rebar3使用.md b/src/docs/rebar3使用.md new file mode 100644 index 0000000..af293c5 --- /dev/null +++ b/src/docs/rebar3使用.md @@ -0,0 +1,83 @@ +# 安装 + 1)[直接下载](https://s3.amazonaws.com/rebar3/rebar3) + 安装到本地 ./rebar3 local install + 升级版本 rebar3 local upgrade + 2)源码安装 + $ git clone https://github.com/erlang/rebar3.git + $ cd rebar3 + $ ./bootstrap + $ ./rebar3 local install + +# 使用rebar3创建新的项目 + 使用rebar3组织项目主要有两种方式: + 1) 作为单个应用程序 + 单个应用程序项目在目录的根目录中包含一个单独的顶级应用程序,其Erlang源模块直接位于src/目录中。 + 2)作为伞行项目 + 伞项目的定义特征是它们可以包含多个顶层的Erlang / OTP应用中,通常内的顶层apps/或lib/目录。这些应用程序中的每一个都可能包含其自己的rebar.config文件。此格式仅适用于具有一个或多个顶级应用程序的发行版。 + + Rebar3带有用于创建这两种类型的项目的模板,可通过rebar3 new