MAX_CHAR

Ben Hanson Ben.Hanson at tfbplc.co.uk
Sat Jun 19 07:34:36 PDT 2010


Hi Justin,

== Quote from Justin Johansson (no at spam.com)'s article
> Ben, are you talking about a lexical value space or a value value space?
> It might help you to solicit a better answer if you posted some code
> such as your template struct, and perhaps some method function signatures.
> It would also help if you explained what you mean by a character type as
> opposed to a string type.  Are you asking about character encodings such
> as UTF-8 or UTF-16 or US-ASCII for example?  Sorry it is not clear in
> your question.
I am converting some template C++ code that can work with char or wchar_t. This code does
not cope with any UTF encoding (I realise this support will ultimately need adding!)
Apparently in D you can do char.max and all I would like to be able to do is that but from
a string type. Here is the code I have so far:

module main;

import std.algorithm;
import std.string;

template regex(StringT)
{
struct basic_string_token
{
    bool _negated = false;
    StringT _charset;

    this(const bool negated_, ref StringT charset_)
    {
        _negated = negated_;
        _charset = charset_;
    }

    void remove_duplicates()
    {
        _charset.sort;
        _charset = squeeze(_charset);
    }

    void normalise()
    {
        const size_t max_chars_ = 256; // Needs conditional here based on char size

        if (_charset.length == max_chars_)
        {
            _negated = !_negated;
            _charset.clear();
        }
        else if (_charset.length > max_chars_ / 2)
        {
            negate();
        }
    }

    void negate()
    {
        _negated = !_negated;
    }
};
}

int main(char[][]argv)
{
    regex!(string).basic_string_token token_;

    token_._charset = "cccbba";
    token_.remove_duplicates();
    return 0;
}

It's in the normalise() routine I would like to know the size of 'char' in.

Thanks,

Ben


More information about the Digitalmars-d mailing list