tango.text.Ascii

License:
BSD style:

Version:
Dec 2006: Initial release

author:
Kris

Placeholder for a selection of ASCII utilities. These generally will not work with utf8, and cannot be easily extended to utf16 or utf32

char[] toLower(char[] src);
Convert to lowercase in-place.

char[] toLower(const(char[]) src, char[] dst);
Convert to lowercase. Returns the converted content in dst.

char[] toUpper(char[] src);
Convert to uppercase in-place.

char[] toUpper(const(char[]) src, char[] dst);
Convert to uppercase. Returns the converted content in dst.

int icompare(const(char[]) s1, const(char[]) s2);
Compare two char[] ignoring case. Returns 0 if equal

int compare(const(char[]) s1, const(char[]) s2);
Compare two char[] with case. Returns 0 if equal

size_t isearch(in char[] src, in char[] pattern);
Return the index position of a text pattern within src, or src.length upon failure.

This is a case-insensitive search (with thanks to Nietsnie)

Examples:
char[20] tmp;

assert (toLower("1bac", tmp) == "1bac");
assert (toLower("1BAC", tmp) == "1bac");
assert (toUpper("1bac", tmp) == "1BAC");
assert (toUpper("1BAC", tmp) == "1BAC");
assert (icompare ("ABC", "abc") is 0);
assert (icompare ("abc", "abc") is 0);
assert (icompare ("abcd", "abc") > 0);
assert (icompare ("abc", "abcd") < 0);
assert (icompare ("ACC", "abc") > 0);

assert (isearch ("ACC", "abc") is 3);
assert (isearch ("ACC", "acc") is 0);
assert (isearch ("aACC", "acc") is 1);



Page generated by Ddoc. Copyright (c) 2006 Kris Bell. All rights reserved