]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/include/string.hh
release: 1.0.1
[lilypond.git] / flower / include / string.hh
index 0e0b9fb4dd05d08baf0f5bb910e273867f8effad..fb8dec55e66030da13c5d5b8622494d7989a4f5c 100644 (file)
 
 #include <string.h>
 #include <iostream.h>
-#include <Rational.h>
-
+#include "arithmetic-operator.hh"
+#include "fproto.hh"
 #include "string-handle.hh"
 
+/* Libg++ also has a String class.  Programming errors can lead to
+  confusion about which String is in use.  Uncomment the following if you have 
+  unexplained crashes after mucking with String
+  */
+
+//  #define String FlowerString
+
 /** 
  
   Intuitive string class. provides 
 class String
 {
 protected:
-    String_handle strh_; 
+  String_handle strh_; 
 
-    bool null_terminated();
+  bool null_terminated ();
     
 public:
 
-    /** init to empty string. This is needed because other
-      constructors are provided.*/
-    String() {  }                  
-    String(Rational);
+  /** init to empty string. This is needed because other
+    constructors are provided.*/
+  String  ();
 
-    /// String s = "abc";
-    String( char const* source ); 
-    String( Byte const* byte_C, int length_i ); 
+  /// String s = "abc";
+  String (char const* source); 
+  String (Byte const* byte_C, int length_i); 
     
-    /// "ccccc"
-    String( char c, int n = 1 );
+  ///  return "new"-ed copy of contents
+  Byte* copy_byte_p () const;
+  char* copy_ch_p() const;
+
+  char const* ch_C () const;
+  Byte const* byte_C () const;
+  char* ch_l ();
+  Byte* byte_l ();
+
+  String &operator =(String const & source);
+
+  /// concatenate s
+  void operator += (char const* s) { strh_ += s; }
+  void operator += (String s);
+
+  bool empty_b  () const;
+#if 0
+  /** is the string empty?
+
+    Ugh-ugh-thank-you-cygnus.  W32 barfs on this
+   */
+  operator bool  () const;
+  {
+    return length_i  (); 
+  }
+#endif
+  void append (String);
+  void prepend (String);
 
-    String( int i , char const *fmt=0);
-    String ( double f , char const* fmt =0);
-    /// 'true' or 'false'
-    String(bool );
+  /**
+    Return a char.  UNSAFE because it may change strlen () result
+   */
+  char &operator [](int n);
+  char operator [](int n) const;
 
-    ///  return a "new"-ed copy of contents
-    Byte* copy_byte_p() const; //  return a "new"-ed copy of contents
+  /// return n leftmost chars
+  String left_str (int n) const;
 
-    char const* ch_C() const;
-    Byte const* byte_C() const;
-    char* ch_l();
-    Byte* byte_l();
+  /// return n rightmost chars
+  String right_str (int n) const;
 
-    /// deprecated; use ch_C()
-    operator char const* () const { return ch_C(); }
-    
-    String &operator =( String const & source );
+  /// return uppercase of *this
+  String upper_str () const;
 
-    /// concatenate s
-    void operator += (char const* s) { strh_ += s; }
-    void operator += (String s);
+  /// return lowercase of *this
+  String lower_str () const;
 
-    void append(String);
-    void prepend(String);
+  /// return the "esrever" of *this
+  String reversed_str () const;
 
-    char operator []( int n ) const { return strh_[n]; }
+  /// return a piece starting at index_i (first char = index_i 0), length n
+  String cut_str (int index_i, int n) const;
 
-    /// return n leftmost chars
-    String left_str( int n ) const;
+  /// cut out a middle piece, return remainder
+  String nomid_str (int index_i, int n) const;
 
-    /// return n rightmost chars
-    String right_str( int n ) const;
+  /// signed comparison,  analogous to memcmp;
+  static int compare_i (String const & s1,const  String& s2);
+       
+  /// index of rightmost c 
+  int index_last_i (char c) const;
 
-    /// return uppercase of *this
-    String upper_str() const;
+  /// index of rightmost element of string  (???)
+  int index_last_i (char const* string) const;
 
-    /// return lowercase of *this
-    String lower_str() const;
+  /// index of leftmost #c#
+  int index_i (char c) const;
 
-    /// return the "esrever" of *this
-    String reversed_str() const;
+  /// index of leftmost occurance of STRING
+  int index_i (String) const;
 
 
-    /// return a piece starting at index_i (first char = index_i 0), length n
-    String mid_str(int index_i, int n ) const;
+  int index_any_i (String) const;
 
-    /// cut out a middle piece, return remainder
-    String nomid_str(int index_i, int n ) const;
+  void to_upper ();
+  void to_lower ();
 
-    /// signed comparison,  analogous to memcmp;
-    static int compare_i(String const & s1,const  String& s2);
-       
-    /// index of rightmost c 
-    int index_last_i( char c) const;
+  /// provide Stream output
+  void print_on (ostream& os) const;
 
-    /// index of rightmost element of string 
-    int index_last_i( char const* string ) const;
+  /// the length of the string
+  int length_i () const;
 
-    int index_i(char c ) const;
-    int index_i(String ) const;
-    int index_any_i(String ) const;
+  /// convert to an integer
+  int value_i () const;
 
-    void to_upper();
-    void to_lower();
-    /// provide Stream output
-    void print_on(ostream& os) const;
+  /// convert to a double
+  double value_f () const;
+};
 
-    /// the length of the string
-    int length_i() const;
+/*
+ better to clutter global namespace, than suffer *ugh, ugh, ugh*
+ implicit conversions.
 
-    // ***** depreciated
-    int len() const {
-       return length_i();
-    }
+ it might be cool to have no type-checking at all in a language,
+ but once there is, having this silently circumvented is a nightmare.
 
-    /// convert to an integer
-    int value_i() const;
+ whenever implicit conversions seem necessary (e.g. operator << ()),
+ use Scalar as the generic type iso String.
+ */
+
+/// for completeness (=handy)
+inline String to_str (String s) { return s; }
+/// "cccc"
+String to_str (char c, int n = 1);
+String to_str (int i, char const* format = 0);
+String to_str (double f , char const* format = 0);
+String to_str (bool b);
+String to_str (char const* format, ... );
+
+/*
+  technically incorrect, but lets keep it here: this is a
+  catch all place for this stuff.
+  */
+  
+#include "international.hh"
 
-    /// convert to a double
-    double value_f() const;
-};
 
 #include "compare.hh"
+INSTANTIATE_COMPARE(String const &, String::compare_i);
+
+#ifdef STRING_UTILS_INLINED
+#ifndef INLINE
+#define INLINE inline
+#endif
+#include "string.icc"
+/* we should be resetting INLINE. oh well. */
+#endif
 
-instantiate_compare(String const &, String::compare_i);
 
 // because char const* also has an operator ==, this is for safety:
-inline bool operator==(String s1, char const* s2){
-    return s1 == String(s2);
+inline bool operator==(String s1, char const* s2)
+{
+  return s1 == String (s2);
 }
 inline bool operator==(char const* s1, String s2)
 {
-    return String(s1)==s2;
+  return String (s1)==s2;
 }
-inline bool operator!=(String s1, char const* s2  ) {
-    return s1!=String(s2);
+inline bool operator!=(String s1, char const* s2 ) {
+  return s1!=String (s2);
 }
 inline bool operator!=(char const* s1,String s2) {
-    return String(s2) !=s1;
+  return String (s2) !=s1;
 }
 
-
-inline String
-operator  + (String s1, String  s2)
-{
-    s1 += s2;
-    return s1;
-}
+IMPLEMENT_ARITHMETIC_OPERATOR (String, +);
 
 inline ostream &
-operator << ( ostream& os, String d )
+operator << (ostream& os, String d)
 {
-    d.print_on(os);
-    return os;
+  d.print_on (os);
+  return os;
 }
 
 
-// String quoteString(String message, String quote);
 
 #endif