Skip to content

Unicode.utf8Validate issue ? #351

Description

@passenger94

Hi,
Many thanks for your work !!!

just used the utf8Validate function in glib/Unicode.d module

public static bool utf8Validate(string str, out string end)

In my understanding end should be made of the chars from start of str to outend, outend beeing the first invalid char in str or pointing after the last char of str if valid.
At the moment the function is "returning" the chars from outend to the end of str or nothing.

public static bool utf8Validate(string str, out string end)
{
    char* start = Str.toStringz(str), outend = null;

    auto __p = g_utf8_validate(start, cast(ptrdiff_t)str.length, &outend) != 0;

    end = Str.toString(start, outend - start);

    return __p;
}
	
unittest
{
    string valid;
    bool success = Unicode.utf8Validate("random text", valid);
    assert(success);
    assert(valid == "random text");
    success = Unicode.utf8Validate("random \xc3\x28text", valid);
    assert(!success);
    assert(valid == "random ");

    success = Unicode.utf8ValidateLen("random text", valid);
    assert(success);
    assert(valid == "random text");
    success = Unicode.utf8ValidateLen("random \xc3\x28text", valid);
    assert(!success);
    assert(valid == "random ");
}

Same goes for utf8ValidateLen() as seen in the unittest.
(code is a fixed proposal - for brevity passing tests with non literal string were omitted )

Did i miss something ?
Cheers

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions