Browse files

Off-by one error after switch to re:run/2

regexp:match(...) counts symbols starting from 0 while re:run(...) - from 1.

Eshell V5.6.5  (abort with ^G)
1> Str = "void* gn_construct_GdkPoint() {".
"void* gn_construct_GdkPoint() {"
2> {match,St,Le} = regexp:match(Str,"gn_construct_.*\\(").
{match,7,22}
3> string:substr(Str,St+13,Le-14).
"GdkPoint"
4>

Eshell V5.6.5  (abort with ^G)
1> Str = "void* gn_construct_GdkPoint() {".
"void* gn_construct_GdkPoint() {"
2> {match,[{St,Le}]} = re:run(Str,"gn_construct_.*\\(").
{match,[{6,22}]}
3> string:substr(Str,St+13,Le-14).
"_GdkPoin"
4> string:substr(Str,St+14,Le-14).
"GdkPoint"
5>

Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
  • Loading branch information...
1 parent f609c30 commit 207589ae2affe08d16ad9c40d7ee8320997481d8 @lemenkov lemenkov committed Jun 7, 2012
Showing with 1 addition and 1 deletion.
  1. +1 −1 priv/generator/generator.erl
View
2 priv/generator/generator.erl
@@ -404,7 +404,7 @@ structs(StructsFile) ->
do_structs(Str, Acc) ->
case re:run(Str,"gn_construct_.*\\(") of
nomatch -> Acc;
- {match,[{St,Le}]} -> [string:substr(Str,St+13,Le-14)|Acc]
+ {match,[{St,Le}]} -> [string:substr(Str,St+14,Le-14)|Acc]
end.
ins_struct(S) -> ets:insert(types,#type{what=struct,cname=S,cast=""}).

0 comments on commit 207589a

Please sign in to comment.