gnash-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnash-dev] Character encoding design


From: Benjamin Wolsey
Subject: Re: [Gnash-dev] Character encoding design
Date: Sun, 19 Oct 2008 16:41:04 +0200

>  > The other difficulty is finding a way of enforcing the interface.
> 
> Worry less about that.  Python has no interface enforcement other than
> the convention that variable names which begin with _ are private
> names.
> 

This is about the minimum header required to use UnicodeString instead
of std::string with a minimum of changes to users of strings. I've
deliberately removed most of the implementation. As you see, it's quite
big. If we want to go this way, I think it should be as easy as possible
to reimplement. Other than providing more documentation about what has
to be there, I don't immediately see a way of doing it.

class ICUString
{
public:

    class ICUStringIterator
    {
    public:
        ICUStringIterator(const UnicodeString& str);

        ICUStringIterator& operator++(void);

        boost::int32_t operator*();
    };

    typedef ICUStringIterator const_iterator;
    
    const_iterator begin();

    const_iterator end();

    typedef std::size_t size_type;

    static const size_type npos = static_cast<size_type>(-1);

    typedef boost::int32_t result_type;

    /// Return a hash of the string. Needed by boost::hash for use in
    /// boost::multi_index.
    boost::int32_t hash() const;

    ICUString(const std::string& str = std::string(),
            bool useCodepage = false);

    ICUString(const UnicodeString& str);

    struct StringNoCaseLessThan
    {
        bool operator()(const ICUString& a, const ICUString& b);
    };

    // Copy constructor
    ICUString(const ICUString& other);

    ICUString(const char* str);

    ICUString& insert(size_type pos, const ICUString& other);

    ICUString& erase(size_type pos, size_type length = npos);

    ICUString operator+(const ICUString& other) const;

    ICUString& operator+=(const ICUString& other);

    size_type length() const;

    bool empty() const;

    size_type find(const ICUString& f, size_type pos = 0) const;

    /// Find the last occurrence of an entire string.
    //
    /// @param f    The string to find.
    /// @param pos  The position to start a reverse search from.
    /// @return     The position of the last occurrence of f, or
    ///             npos if the string is not found.
    //
    ///             Note that this function may not actually perform
    ///             a reverse search, but logically starts looking
    ///             backwards from position pos.
    size_type lastIndexOf(const ICUString& f, size_type pos = npos) const;

    /// Return part of the string
    //
    /// @param start    The index of the first character.
    /// @param length   The number of characters to copy.
    /// @return         A copy of the substring.
    ICUString substr(size_type start, size_type length = npos) const;

    /// Convert the string to lower case.
    void toLower();

    /// Convert the string to upper case.
    void toUpper();

    /// Return an upper case copy using ascii case conversion
    //
    /// @return     A std::string copy of the string. This method
    ///             does not change the original string.
    std::string toUpperAsciiCopy() const;

    /// Return a upper case copy of the string.
    //
    /// @return     A std::string copy of the string. This method
    ///             does not change the original string.
    std::string toUpperCopy() const;

    /// Return a lower case copy using ascii case conversion
    //
    /// @return     A std::string copy of the string. This method
    ///             does not change the original string.
    std::string toLowerAsciiCopy() const;

    /// Return a lower case copy of the string.
    //
    /// @return     A std::string copy of the string. This method
    ///             does not change the original string.
    std::string toLowerCopy() const;

    /// Get the character at an index in the string
    //
    /// @param pos      The index of the required character.
    /// @return         The character represented as a short.
    //
    ///                 Note that the actual value of the character
    ///                 may be greater than 16 bits, but ActionScript
    ///                 currently only handles characters up to 65535
    boost::uint16_t operator[](size_type pos) const;

    /// Convert the string to a UTF-8 std::string
    std::string str() const;

    /// Equality operator
    bool operator==(const ICUString& other) const;

    /// Inequality operator
    bool operator!=(const ICUString& other) const;

    /// Comparison (less than) operator
    bool operator<(const ICUString& other) const;

    /// Comparison (greater than) operator
    bool operator>(const ICUString& other) const;

    /// Assignment operator
    ICUString& operator=(const ICUString& other);
};

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil


reply via email to

[Prev in Thread] Current Thread [Next in Thread]