/*------------------------------------------------------------------------------
 src/lib/dj/djStr.h
 
 Copyright (c) 2004-2006 Darby Johnston.
 All rights reserved.
 Use is subject to license terms.
------------------------------------------------------------------------------*/

#ifndef DJ_STR_H
#define DJ_STR_H
#include <djList.h>

namespace dj {

// String type.
//
typedef List<char> Str;

// String lists.
//
typedef List<Str> StrList;
typedef ListIt<char> StrIt;
typedef ConstListIt<char> ConstStrIt;
typedef ListIt<Str> StrListIt;
typedef ConstListIt<Str> ConstStrListIt;

// String specialization.
//
template <>
class List<char> : public _List<char> {
public:

  List();
  List(const List<char> &);
  List(char);
  List(const char *, int size = -1);
  ~List();
  
  // Set.
  //
  List<char> & operator = (const List<char> &);
  
  // Get.
  //
  bool isNull() const { return ! size(); }
  
  // Conversion.
  //
  const char * toAscii() const;
  //operator const char * () const { return toAscii(); }
  
  // Formatting.
  //
  const Str arg(int, int width = 0, char fill = ' ') const;
  const Str arg(
    double, int width = 0, int precision = 6, char fill = ' '
  ) const;
  const Str arg(const Str &, int width = 0, char fill = ' ') const;
  const Str arg(const StrList &, int width = 0, char fill = ' ') const;

private:

  char * _ascii;
};

// Functions.
//
const Str lowercase(const Str &);
const Str uppercase(const Str &);

// Comparison.
//
bool compare(const Str &, const Str &, int size = -1);
bool compareCase(const Str &, const Str &, int size = -1);
int  compareSort(const Str &, const Str &, int size = -1);
int  compareCaseSort(const Str &, const Str &, int size = -1);
bool operator < (const Str &, const Str &);
bool operator > (const Str &, const Str &);
bool match(const Str &, const Str & pattern);
bool isDigit(char);

// Conversion.
//
int      toInt(const Str &);
uint64_t toLong(const Str &);
double   toFloat(const Str &);

char * toAscii(const Str &);
int    toAscii(const Str &, char *, int size, bool terminate = true);

const Str toStr(int);
const Str toStr(uint64_t);
const Str toStr(double, int precision = 6);
const Str toStr(const char *, int size = -1);

template <class T> const StrList toStrList(const List<T> &);
const IntList toIntList(const StrList &);

// Labels.
//
inline const StrList boolStr()
  { return StrList() + Str("False") + Str("True"); }

// XXX
//
#define DJ_CSTR_SIZE 256

}

#include <djStr_.h>
#endif
