// ---------------------------------------------------------------------------
// - Unicode.hpp                                                             -
// - standard object library - unicode functions class definition            -
// ---------------------------------------------------------------------------
// - This program is free software;  you can redistribute it  and/or  modify -
// - it provided that this copyright notice is kept intact.                  -
// -                                                                         -
// - This program  is  distributed in  the hope  that it will be useful, but -
// - without  any  warranty;  without  even   the   implied    warranty   of -
// - merchantability or fitness for a particular purpose.  In no event shall -
// - the copyright holder be liable for any  direct, indirect, incidental or -
// - special damages arising in any way out of the use of this software.     -
// ---------------------------------------------------------------------------
// - copyright (c) 1999-2006 amaury darsch                                   -
// ---------------------------------------------------------------------------

#ifndef  AFNIX_UNICODE_HPP
#define  AFNIX_UNICODE_HPP

#ifndef  AFNIX_STRING_HPP
#include "String.hpp"
#endif

namespace afnix {

  /// The Unicode class is a collection of static convenient functions that
  /// manipulates the unicode representation. The internal representation of
  /// a unicode character is quad type in host representation.
  /// @author amaury darsch

  class Unicode {
  public:
    /// convert a unicode character to a native character if possible
    /// @param value the value to convert
    static char tochar (const t_quad value);

    /// convert a native character to a unicode character
    /// @param value the value to convert
    static t_quad toquad (const char value);

    /// convert a string to a unicode character
    /// @param value the string value representation to convert
    static t_quad toquad (const String& value);

    /// convert a unicode character to a string
    /// @param value the native value to convert
    static String tostring (const t_quad value);

    /// convert a unicode character to a literal string
    /// @param value the native value to convert
    static String toliteral (const t_quad value);

    /// @return the length of an unicode string
    static long strlen (const t_quad* s);

    /// compare two strings and returns true if they are equals.
    /// @param s1 the first string
    /// @param s2 the second string
    /// @return true if the string are equals or both null
    static bool strcmp (const t_quad* s1, const char* s2);

    /// compare two strings and returns true if they are equals.
    /// @param s1 the first string
    /// @param s2 the second string
    /// @return true if the string are equals or both null
    static bool strcmp (const t_quad* s1, const t_quad* s2);
    
    /// compare two strings and returns true if they are equals for a number of
    /// characters. This function is safe with null pointer.
    /// @param s1 the first string
    /// @param s2 the second string
    /// @param size the number of characters to compare
    /// @return true if the string are equals or both null
    static bool strncmp (const t_quad* s1, const char* s2, const long size);

    /// compare two strings and returns true if they are equals for a number of
    /// characters. This function is safe with null pointer.
    /// @param s1 the first string
    /// @param s2 the second string
    /// @param size the number of characters to compare
    /// @return true if the string are equals or both null
    static bool strncmp (const t_quad* s1, const t_quad* s2, const long size);

    /// compare two strings and returns true if s1 is less than s2.
    /// @param s1 the first string
    /// @param s2 the second string
    /// @return true if the string are equals or both null
    static bool strlth (const t_quad* s1, const char* s2);
 
    /// compare two strings and returns true if s1 is less than s2.
    /// @param s1 the first string
    /// @param s2 the second string
    /// @return true if the string are equals or both null
    static bool strlth (const t_quad* s1, const t_quad* s2);
    
    /// compare two strings and returns true if s1 is less equal than s2.
    /// @param s1 the first string
    /// @param s2 the second string
    /// @return true if the string are equals or both null
    static bool strleq (const t_quad* s1, const char* s2);

    /// compare two strings and returns true if s1 is less equal than s2.
    /// @param s1 the first string
    /// @param s2 the second string
    /// @return true if the string are equals or both null
    static bool strleq (const t_quad* s1, const t_quad* s2);
    
    /// @return an unicode array from an ascii character
    static t_quad* strmak (const char value);

    /// @return an unicode array from an unicode character
    static t_quad* strmak (const t_quad value);

    /// @return an unicode array from an ascii string
    static t_quad* strdup (const char* s);

    /// @return an unicode array from an unicode string
    static t_quad* strdup (const t_quad* s);

    /// copy a c-string from a source to a unicode destination
    /// @param dst the destination string
    /// @param src the source string
    static void strcpy (t_quad* dst, const char* src);

    /// copy a unicode string from a source to a unicode destination
    /// @param dst the destination string
    /// @param src the source string
    static void strcpy (t_quad* dst, const t_quad* src);

    /// concatenate a c-string with a unicode string
    /// @param dst the destination string
    /// @param src the source string
    static void strcat (t_quad* dst, const char* src);

    /// concatenate a unicode string with a unicode string
    /// @param dst the destination string
    /// @param src the source string
    static void strcat (t_quad* dst, const t_quad* src);

    /// remove the leading blank and tab and return a new string
    /// @param s the original string
    /// @return a new clean string
    static t_quad* rmlead (const char* s);
    
    /// remove the leading blank and tab and return a new string
    /// @param s the original string
    /// @return a new clean string
    static t_quad* rmlead (const t_quad* s);
    
    /// remove the trailing blank and tab and return a new string
    /// @param s the original string
    /// @return a new clean string
    static t_quad* rmtrail (const char* s);
    
    /// remove the trailing blank and tab and return a new string
    /// @param s the original string
    /// @return a new clean string
    static t_quad* rmtrail (const t_quad* s);
    
    /// convert the string to lower case
    /// @param s the original string
    /// @return a new lower case string
    static t_quad* tolower (const char* s);

    /// convert the string to lower case
    /// @param s the original string
    /// @return a new lower case string
    static t_quad* tolower (const t_quad* s);

    /// convert the string to upper case
    /// @param s the original string
    /// @return a new upper case string
    static t_quad* toupper (const char* s);

    /// convert the string to upper case
    /// @param s the original string
    /// @return a new upper case string
    static t_quad* toupper (const t_quad* s);

    /// @return true if the unicode character is a lower character
    static bool islower (const t_quad value);

    /// @return true if the unicode character is an upper character
    static bool isupper (const t_quad value);

    /// @return true if the unicode character is a letter
    static bool isletter (const t_quad value);

    /// @return true if the unicode character is a digit
    static bool isdigit (const t_quad value);

    /// @return true if the unicode character is alpha
    static bool isalpha (const t_quad value);

    /// @return true if the unicode character is a blank or tab
    static bool isblank (const t_quad value);

    /// @return true if the unicode character is an ascii character
    static bool isascii (const t_quad value);

    /// @return true if the unicode character is a latin character
    static bool islatin (const t_quad value);

    /// @return true if the unicode character is an hexadecimal character
    static bool ishexa (const t_quad value);

    /// @return true if the unicode character is an afnix character
    static bool isafnix (const t_quad value);

    /// @return a unicode character encoding
    static char* encode (const t_quad c);

    /// @return a string encoding of a unicode string
    static char* encode (const t_quad* s);

    /// @return a string encoding of a buffer by size
    static char* encode (const t_quad* s, const long size);

    /// @return a unicode string by decoding a character buffer
    static t_quad* decode (const char* s);

    /// @return a unicode string by decoding a character buffer by size
    static t_quad* decode (const char* s, const long size);
  };
}

#endif
