Skip to content

Commit

Permalink
giving a parse error for invalid utf-8 in bare string literals
Browse files Browse the repository at this point in the history
fixes part of issue #10
  • Loading branch information
JeffBezanson committed Jul 9, 2011
1 parent 7031bf6 commit 6614948
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
9 changes: 9 additions & 0 deletions doc/todo
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,15 @@ and emit a type check if we inline

-------------------------------------------------------------------------------

table updates
most general form is h[k] = f(get(h, k, default))

more efficient implementation would be:
i = findref(h,k)
putref(h,i,f(getref(h,i,default)))

-------------------------------------------------------------------------------

issues 4/16/11

clone(Array{Any,1}) matches both
Expand Down
2 changes: 1 addition & 1 deletion src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ value_t fl_invoke_julia_macro(value_t *args, uint32_t nargs)
JL_GC_POP();
ios_printf(jl_current_output_stream(), "\n");
jl_show(jl_exception_in_transit);
ios_printf(jl_current_output_stream(), "\n");
//ios_printf(jl_current_output_stream(), "\n");
return fl_cons(symbol("error"), FL_NIL);
}
// protect result from GC, otherwise it could be freed during future
Expand Down
9 changes: 9 additions & 0 deletions src/flisp/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,14 @@ value_t fl_stringtonumber(value_t *args, uint32_t nargs)
return n;
}

value_t fl_string_isutf8(value_t *args, u_int32_t nargs)
{
argcount("string.isutf8", nargs, 1);
char *s = tostring(args[0], "string.isutf8");
size_t len = cv_len((cvalue_t*)ptr(args[0]));
return u8_isvalid(s, len) ? FL_T : FL_F;
}

static builtinspec_t stringfunc_info[] = {
{ "string", fl_string },
{ "string?", fl_stringp },
Expand All @@ -400,6 +408,7 @@ static builtinspec_t stringfunc_info[] = {
{ "string.reverse", fl_string_reverse },
{ "string.encode", fl_string_encode },
{ "string.decode", fl_string_decode },
{ "string.isutf8", fl_string_isutf8 },

{ "char.upcase", fl_char_upcase },
{ "char.downcase", fl_char_downcase },
Expand Down
5 changes: 4 additions & 1 deletion src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,10 @@
(let ((ps (parse-string-literal s)))
(if (cdr ps)
`(macrocall str ,(car ps))
(unescape-string (car ps)))))
(let ((str (unescape-string (car ps))))
(if (not (string.isutf8 str))
(error "invalid utf-8 sequence"))
str))))

;; macro call
((eqv? t #\@)
Expand Down

0 comments on commit 6614948

Please sign in to comment.