/ / メモ
2010-03-13

2009-08-21-1 のコードを,
std.regex を使って書き直し。

import std.string;
import std.regex;
import std.c.stdlib;
import core.stdc.errno;
byte[] decodeChunked(byte[] src)
{
    string entityBody;
    char* endptr;
    auto reg = regex(q"{[\da-fA-F]+[^\r\n]*\r\n}"); //16進

    auto m = match(cast(char[])src,reg);

    errno = 0;
    auto chunkSize = strtol(m.hit.toStringz,&endptr,16);
    if (errno == ERANGE){}
    if (m.hit.toStringz == endptr) {}

    while(chunkSize > 0)
    {
        entityBody ~= m.post[0 .. chunkSize];
        m = match(m.post[chunkSize .. $],reg);
        errno = 0;
        chunkSize = strtol(m.hit.toStringz,&endptr,16);
        if (errno == ERANGE){}
        if (m.hit.toStringz == endptr) {}
    }

    return entityBody;
}

トラックバック http://mikanya.dip.jp/memo/2010-03-13-2