Skip to content

Commit

Permalink
Replace all invalid uses of countUntil() with std.string.indexOf(). F…
Browse files Browse the repository at this point in the history
…ixes #205.
  • Loading branch information
s-ludwig committed Mar 30, 2013
1 parent ba5777e commit 0bf7ccb
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 71 deletions.
12 changes: 6 additions & 6 deletions source/vibe/db/mongo/connection.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public import vibe.data.bson;
import vibe.core.log;
import vibe.core.net;

import std.algorithm;
import std.algorithm : splitter;
import std.array;
import std.conv;
import std.exception;
Expand Down Expand Up @@ -412,9 +412,9 @@ bool parseMongoDBUrl(out MongoClientSettings cfg, string url)
// Reslice to get rid of 'mongodb://'
tmpUrl = tmpUrl[10..$];

auto slashIndex = countUntil(tmpUrl, "/");
auto slashIndex = tmpUrl.indexOf("/");
if( slashIndex == -1 ) slashIndex = tmpUrl.length;
auto authIndex = tmpUrl[0 .. slashIndex].countUntil('@');
auto authIndex = tmpUrl[0 .. slashIndex].indexOf('@');
sizediff_t hostIndex = 0; // Start of the host portion of the URL.

// Parse out the username and optional password.
Expand All @@ -423,7 +423,7 @@ bool parseMongoDBUrl(out MongoClientSettings cfg, string url)
// Set the host start to after the '@'
hostIndex = authIndex + 1;

auto colonIndex = tmpUrl[0..authIndex].countUntil(':');
auto colonIndex = tmpUrl[0..authIndex].indexOf(':');
if(colonIndex != -1)
{
cfg.username = tmpUrl[0..colonIndex];
Expand Down Expand Up @@ -468,7 +468,7 @@ bool parseMongoDBUrl(out MongoClientSettings cfg, string url)
return true;
}

auto queryIndex = tmpUrl[slashIndex..$].countUntil("?");
auto queryIndex = tmpUrl[slashIndex..$].indexOf("?");
if(queryIndex == -1){
// No query string. Remaining string is the database
queryIndex = tmpUrl.length;
Expand All @@ -485,7 +485,7 @@ bool parseMongoDBUrl(out MongoClientSettings cfg, string url)
foreach(c; optionMatch)
{
auto optionString = c["option"];
auto separatorIndex = countUntil(optionString, "=");
auto separatorIndex = optionString.indexOf("=");
// Per the mongo docs the option names are case insensitive.
auto option = optionString[0 .. separatorIndex];
auto value = optionString[(separatorIndex+1) .. $];
Expand Down
6 changes: 3 additions & 3 deletions source/vibe/http/log.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import vibe.core.file;
import vibe.core.log;
import vibe.http.server;

import std.algorithm;
import std.array;
import std.conv;
import std.exception;
import std.string;


class HttpConsoleLogger : HttpLogger {
Expand Down Expand Up @@ -92,7 +92,7 @@ string formatApacheLog(string format, HttpServerRequest req, HttpServerResponse
while( format.length > 0 ) {
final switch(state) {
case State.Init:
auto idx = format.countUntil('%');
auto idx = format.indexOf('%');
if( idx < 0 ) {
ln.put( format );
format = "";
Expand Down Expand Up @@ -142,7 +142,7 @@ string formatApacheLog(string format, HttpServerRequest req, HttpServerResponse
}
break;
case State.Key:
auto idx = format.countUntil('}');
auto idx = format.indexOf('}');
enforce(idx > -1, "Missing '}'");
key = format[0 .. idx];
format = format[idx+1 .. $];
Expand Down
6 changes: 3 additions & 3 deletions source/vibe/http/rest.d
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ private string generateRestInterfaceSubInterfaces(I)()
alias ReturnType!FT RT;
static if( is(RT == interface) ){
static assert(PTypes.length == 0, "Interface getters may not have parameters.");
if( tps.countUntil(RT.stringof) < 0 ){
if (!tps.canFind(RT.stringof)) {
tps ~= RT.stringof;
string implname = RT.stringof~"Impl";
ret ~= format(
Expand Down Expand Up @@ -586,7 +586,7 @@ private string generateRestInterfaceSubInterfaceInstances(I)()
alias ReturnType!FT RT;
static if( is(RT == interface) ){
static assert(PTypes.length == 0, "Interface getters may not have parameters.");
if( tps.countUntil(RT.stringof) < 0 ){
if (!tps.canFind(RT.stringof)) {
tps ~= RT.stringof;
string implname = RT.stringof~"Impl";

Expand Down Expand Up @@ -623,7 +623,7 @@ private string generateRestInterfaceSubInterfaceRequestFilter(I)()
alias ReturnType!FT RT;
static if( is(RT == interface) ){
static assert(PTypes.length == 0, "Interface getters may not have parameters.");
if( tps.countUntil(RT.stringof) < 0 ){
if (!tps.canFind(RT.stringof)) {
tps ~= RT.stringof;
string implname = RT.stringof~"Impl";

Expand Down
12 changes: 6 additions & 6 deletions source/vibe/http/server.d
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import vibe.utils.string;
import vibe.core.file;

import core.vararg;
import std.algorithm : countUntil, map, min;
import std.algorithm : canFind, map, min;
import std.array;
import std.conv;
import std.datetime;
Expand Down Expand Up @@ -132,9 +132,9 @@ private void listenHttpPlain(HttpServerSettings settings, HttpServerRequestDeleg
enforce(settings.sslContext is lst.sslContext,
"A HTTP server is already listening on "~addr~":"~to!string(settings.port)~
" but the SSL context differs.");
foreach( ctx; g_contexts ){
if( ctx.settings.port != settings.port ) continue;
if( countUntil(ctx.settings.bindAddresses, addr) < 0 ) continue;
foreach (ctx; g_contexts) {
if (ctx.settings.port != settings.port) continue;
if (!ctx.settings.bindAddresses.canFind(addr)) continue;
/*enforce(ctx.settings.hostName != settings.hostName,
"A server with the host name '"~settings.hostName~"' is already "
"listening on "~addr~":"~to!string(settings.port)~".");*/
Expand Down Expand Up @@ -1138,9 +1138,9 @@ private bool handleRequest(Stream http_stream, string peer_address, HTTPServerLi

// setup compressed output
if( auto pae = "Accept-Encoding" in req.headers ){
if( countUntil(*pae, "gzip") >= 0 ){
if (canFind(*pae, "gzip")) {
res.headers["Content-Encoding"] = "gzip";
} else if( countUntil(*pae, "deflate") >= 0 ){
} else if (canFind(*pae, "deflate")) {
res.headers["Content-Encoding"] = "deflate";
}
}
Expand Down
6 changes: 3 additions & 3 deletions source/vibe/inet/path.d
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
module vibe.inet.path;

import std.algorithm;
import std.algorithm : canFind, min;
import std.array;
import std.conv;
import std.exception;
Expand All @@ -32,7 +32,7 @@ struct Path {
this(string pathstr)
{
m_nodes = cast(immutable)splitPath(pathstr);
m_absolute = (pathstr.startsWith("/") || m_nodes.length > 0 && m_nodes[0].toString().countUntil(':')>0);
m_absolute = (pathstr.startsWith("/") || m_nodes.length > 0 && m_nodes[0].toString().indexOf(':')>0);
m_endsWithSlash = pathstr.endsWith("/");
foreach( e; m_nodes ) assert(e.toString().length > 0, "Empty path nodes not allowed: "~pathstr);
}
Expand Down Expand Up @@ -232,7 +232,7 @@ struct PathEntry {

this(string str)
{
assert(str.countUntil('/') < 0 && str.countUntil('\\') < 0);
assert(!str.canFind('/') && !str.canFind('\\'));
m_name = str;
}

Expand Down
15 changes: 7 additions & 8 deletions source/vibe/inet/url.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public import vibe.inet.path;

import vibe.textfilter.urlencode;

import std.algorithm;
import std.array;
import std.conv;
import std.exception;
Expand Down Expand Up @@ -56,7 +55,7 @@ struct Url {
auto str = url_string;
enforce(str.length > 0, "Empty URL.");
if( str[0] != '/' ){
auto idx = str.countUntil(':');
auto idx = str.indexOf(':');
enforce(idx > 0, "No schema in URL:"~str);
m_schema = str[0 .. idx];
str = str[idx+1 .. $];
Expand All @@ -75,13 +74,13 @@ struct Url {
str = str[2 .. $];
goto default;
default:
auto si = str.countUntil('/');
auto si = str.indexOf('/');
if( si < 0 ) si = str.length;
auto ai = str[0 .. si].countUntil('@');
auto ai = str[0 .. si].indexOf('@');
sizediff_t hs = 0;
if( ai >= 0 ){
hs = ai+1;
auto ci = str[0 .. ai].countUntil(':');
auto ci = str[0 .. ai].indexOf(':');
if( ci >= 0 ){
m_username = str[0 .. ci];
m_password = str[ci+1 .. ai];
Expand All @@ -90,7 +89,7 @@ struct Url {
}

m_host = str[hs .. si];
auto pi = m_host.countUntil(':');
auto pi = m_host.indexOf(':');
if(pi > 0) {
enforce(pi < m_host.length-1, "Empty port in URL.");
m_port = to!ushort(m_host[pi+1..$]);
Expand Down Expand Up @@ -175,13 +174,13 @@ struct Url {
/// ditto
@property void localURI(string str)
{
auto ai = str.countUntil('#');
auto ai = str.indexOf('#');
if( ai >= 0 ){
m_anchor = str[ai+1 .. $];
str = str[0 .. ai];
}

auto qi = str.countUntil('?');
auto qi = str.indexOf('?');
if( qi >= 0 ){
m_queryString = str[qi+1 .. $];
str = str[0 .. qi];
Expand Down
12 changes: 6 additions & 6 deletions source/vibe/mail/smtp.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import vibe.inet.message;
import vibe.stream.operations;
import vibe.stream.ssl;

import std.algorithm;
import std.base64;
import std.conv;
import std.exception;
import std.string;


/**
Expand Down Expand Up @@ -183,8 +183,8 @@ void sendMail(SmtpClientSettings settings, Mail mail)
while(true){ // simple skipping of
auto ln = cast(string)conn.readLine();
logDebug("EHLO response: %s", ln);
auto sidx = ln.countUntil(' ');
auto didx = ln.countUntil('-');
auto sidx = ln.indexOf(' ');
auto didx = ln.indexOf('-');
if( sidx > 0 && (didx < 0 || didx > sidx) ){
enforce(ln[0 .. sidx] == "250", "Server not ready (response "~ln[0 .. sidx]~")");
break;
Expand Down Expand Up @@ -253,7 +253,7 @@ void sendMail(SmtpClientSettings settings, Mail mail)
private void expectStatus(InputStream conn, int expected_status, string in_response_to)
{
string ln = cast(string)conn.readLine();
auto sp = ln.countUntil(' ');
auto sp = ln.indexOf(' ');
if( sp < 0 ) sp = ln.length;
auto status = to!int(ln[0 .. sp]);
enforce(status == expected_status, "Expected status "~to!string(expected_status)~" in response to "~in_response_to~", got "~to!string(status)~": "~ln[sp .. $]);
Expand All @@ -262,14 +262,14 @@ private void expectStatus(InputStream conn, int expected_status, string in_respo
private int recvStatus(InputStream conn)
{
string ln = cast(string)conn.readLine();
auto sp = ln.countUntil(' ');
auto sp = ln.indexOf(' ');
if( sp < 0 ) sp = ln.length;
return to!int(ln[0 .. sp]);
}

private string addressMailPart(string str)
{
auto idx = str.countUntil('<');
auto idx = str.indexOf('<');
if( idx < 0 ) return str;
str = str[idx .. $];
enforce(str[$-1] == '>', "Malformed email address field: '"~str~"'.");
Expand Down
Loading

0 comments on commit 0bf7ccb

Please sign in to comment.