Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Jacky Zhao patch utf8 applied

  • Loading branch information...
commit af7705c7fea70e99a4e16652b577444ee88ab315 1 parent 8990d30
Michal Ptaszek authored
View
19 lib/wpart-1.4/src/utf8_api.erl
@@ -2,13 +2,20 @@
%% written by Per Gustafsson http://user.it.uu.se/~pergu
-module(utf8_api).
--export([ulength/1]).
+-export([ulength/1, ustring/1]).
%% @doc takes regular string encoded in utf.
ulength(String) ->
{Res, List} = utf8:from_binary(list_to_binary(String)),
- Length = if
- Res == ok -> length(List);
- true -> Res
- end,
- Length.
+ if
+ Res == ok -> length(List);
+ true -> Res
+ end.
+
+ustring(RawString) ->
+ case (catch utf8:from_binary(list_to_binary(RawString))) of
+ {ok, String} ->
+ String;
+ _ ->
+ RawString
+ end.
View
7 lib/wparts-1.4/src/wtype_password.erl
@@ -45,7 +45,8 @@ validate({Types, undefined}) ->
end
end;
-validate({Types, String}) when is_list(String) ->
+validate({Types, RawString}) when is_list(RawString) ->
+ String = utf8_api:ustring(RawString),
case wpart_valid:is_private(Types) of
true ->
{ok, String};
@@ -80,7 +81,7 @@ check_confirm0(String, _) ->
check_min_length(String, Types) ->
case lists:keysearch(min_length, 1, Types) of
{value, {min_length, Min}} ->
- N = utf8_api:ulength(String),
+ N = length(String),
if
N < Min ->
{error, {too_short, String}};
@@ -94,7 +95,7 @@ check_min_length(String, Types) ->
check_max_length(String, Types) ->
case lists:keysearch(max_length, 1, Types) of
{value, {max_length, Max}} ->
- N = utf8_api:ulength(String),
+ N = length(String),
if
N > Max ->
{error, {too_long, String}};
View
7 lib/wparts-1.4/src/wtype_string.erl
@@ -45,7 +45,8 @@ validate({Types,undefined}) ->
end
end;
-validate({Types,String}) when is_list(String) ->
+validate({Types,RawString}) when is_list(RawString) ->
+ String = utf8_api:ustring(RawString),
case wpart_valid:is_private(Types) of
true ->
{ok, String};
@@ -71,7 +72,7 @@ validate({Types,String}) when is_list(String) ->
check_min_length(String, Types) ->
case lists:keysearch(min_length, 1, Types) of
{value, {min_length, Min}} ->
- N = utf8_api:ulength(String),
+ N = length(String),
if
N < Min ->
{error, {too_short, String}};
@@ -85,7 +86,7 @@ check_min_length(String, Types) ->
check_max_length(String, Types) ->
case lists:keysearch(max_length, 1, Types) of
{value, {max_length, Max}} ->
- N = utf8_api:ulength(String),
+ N = length(String),
if
N > Max ->
{error, {too_long, String}};
View
7 lib/wparts-1.4/src/wtype_text.erl
@@ -43,7 +43,8 @@ validate({Types, undefined}) ->
end
end;
-validate({Types,Text}) when is_list(Text) ->
+validate({Types,RawText}) when is_list(RawText) ->
+ Text = utf8_api:ustring(RawText),
case wpart_valid:is_private(Types) of
true ->
{ok, Text};
@@ -70,7 +71,7 @@ validate({Types, Text}) ->
check_min_length(String, Types) ->
case lists:keysearch(min_length, 1, Types) of
{value, {min_length, Min}} ->
- X = utf8_api:ulength(String),
+ X = length(String),
if
X < Min ->
{error, {too_short, String}};
@@ -84,7 +85,7 @@ check_min_length(String, Types) ->
check_max_length(String, Types) ->
case lists:keysearch(max_length, 1, Types) of
{value, {max_length, Max}} ->
- X = utf8_api:ulength(String),
+ X = length(String),
if
X > Max ->
{error, {too_long, String}};

0 comments on commit af7705c

Please sign in to comment.
Something went wrong with that request. Please try again.