Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace foreach(dchar; s) loop with explicit for+range #327

Merged
merged 2 commits into from
Sep 27, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions source/vibe/textfilter/html.d
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ string htmlEscape(string str)
*/
void filterHTMLEscape(R)(ref R dst, string str)
{
foreach( dchar ch; str )
filterHTMLEscape(dst, ch, HTMLEscapeFlags.escapeNewline);
for( ; !str.empty; str.popFront() )
filterHTMLEscape(dst, str.front, HTMLEscapeFlags.escapeNewline);
}

/// Deprecated compatibility alias
Expand All @@ -59,8 +59,8 @@ string htmlAttribEscape(string str)
*/
void filterHTMLAttribEscape(R)(ref R dst, string str)
{
foreach( dchar ch; str )
filterHTMLEscape(dst, ch, HTMLEscapeFlags.escapeNewline|HTMLEscapeFlags.escapeQuotes);
for( ; !str.empty; str.popFront() )
filterHTMLEscape(dst, str.front, HTMLEscapeFlags.escapeNewline|HTMLEscapeFlags.escapeQuotes);
}

/// Deprecated compatibility alias
Expand All @@ -86,9 +86,9 @@ string htmlAllEscape()(string str)
*/
void filterHTMLAllEscape(R)(ref R dst, string str)
{
foreach( dchar ch; str ){
for( ; !str.empty; str.popFront() ){
dst.put("&#");
dst.put(to!string(cast(int)ch));
dst.put(to!string(cast(uint)str.front));
dst.put(';');
}
}
Expand All @@ -103,8 +103,8 @@ deprecated("Please use filterHTMLAllEscape instead.") alias filterHtmlAllEscape
string htmlEscapeMin(string str)
{
auto dst = appender!string();
foreach( dchar ch; str )
filterHTMLEscape(dst, ch, HTMLEscapeFlags.escapeMinimal);
for( ; !str.empty; str.popFront() )
filterHTMLEscape(dst, str.front, HTMLEscapeFlags.escapeMinimal);
return dst.data();
}

Expand All @@ -118,7 +118,7 @@ void filterHTMLEscape(R)(ref R dst, dchar ch, HTMLEscapeFlags flags = HTMLEscape
default:
if( flags & HTMLEscapeFlags.escapeUnknown ){
dst.put("&#");
dst.put(to!string(cast(int)ch));
dst.put(to!string(cast(uint)ch));
dst.put(';');
} else dst.put(ch);
break;
Expand All @@ -129,10 +129,10 @@ void filterHTMLEscape(R)(ref R dst, dchar ch, HTMLEscapeFlags flags = HTMLEscape
case '\r', '\n':
if( flags & HTMLEscapeFlags.escapeNewline ){
dst.put("&#");
dst.put(to!string(cast(int)ch));
dst.put(to!string(cast(uint)ch));
dst.put(';');
} else dst.put(ch);
break;
break;
case 'a': .. case 'z': goto case;
case 'A': .. case 'Z': goto case;
case '0': .. case '9': goto case;
Expand Down