]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/string.hh
release: 0.0.30
[lilypond.git] / flower / string.hh
index d3d27742610a1a38724e2d8886a2bd1c5ff30a78..e58f6146997405e7471a6e24316909e100c089c3 100644 (file)
 
 #include <string.h>
 #include <iostream.h>
-
+#include <Rational.h>
 
 #include "stringutil.hh"
 
 /// the smart string class.
+/** 
+
+  Intuitive string class. provides 
+
+  ref counting through #String_handle#
+
+  conversion from bool, int, double, char *, char.
+
+  conversion to int, upcase, downcase
+
+
+  printable. 
+
+  indexing (pos, posAny, lastPos)
+
+  cutting (left, right, mid)
+
+  concat (+=, +)
+
+  signed comparison (<, >, ==, etc)
+
+  No operator[] is provided, since this would be enormously  slow. If needed,
+  convert to const char *. 
+*/
 class String
 {
 protected:
@@ -27,9 +51,9 @@ protected:
 
 public:
     /// init to ""
-    String() {  }                  
     /** needed because other constructors are provided.*/
-
+    String() {  }                  
+    String(Rational);
     /// String s = "abc";
     String( const char* source ); 
     
@@ -49,9 +73,11 @@ public:
     ///  return a "new"-ed copy of contents
     char *copy_array() const; //  return a "new"-ed copy of contents
 
-    const char *ptr() const;
+    const char *cptr() const;
+    const char *ptr() { return ((const String *)this)->cptr(); }
+
     /// return the data. Don't use for writing the data.
-    operator const char *() const { return ptr(); }
+    operator const char *() const { return cptr(); }
     
     String operator =( const String & source ) { data = source.data; return *this; }
 
@@ -84,19 +110,20 @@ public:
     String nomid(int pos, int n ) const;
 
     /// signed comparison,  analogous to strcmp;
-    int  compare( const char* s ) const;
-
+    static int compare(const String& s1,const  String& s2);
+       
     /// index of rightmost c 
     int lastPos( char c) const;
+
     /// index of rightmost element of string 
     int lastPos( const char* string ) const;
 
     /// index of leftmost c
-    int pos(char c ) const;
     /**
     RETURN:
     0 if not found, else index + 1
     */
+    int pos(char c ) const;
     int pos(const char* string ) const;
     int posAny(const char* string ) const;
 
@@ -113,44 +140,27 @@ public:
     /// the length of the string
     int len() const;
 
-    /// DO NOT MAKE THIS INTO AN OPERATOR
-    bool to_bool() const;
-    /** perl -like string to bool conversion
-     */
 };
-/** 
-
-  Intuitive string class. provides 
-
-  ref counting thru #String_handle#
-
-  conversion from bool, int, double, char *, char.
-
-  conversion to int, upcase, downcase
-
-
-  printable. 
-
-  indexing (pos, posAny, lastPos)
 
-  cutting (left, right, mid)
-
-  concat (+=, +)
-
-  signed comparison (<, >, ==, etc)
-
-  No operator[] is provided, since this would be enormously  slow. If needed,
-  convert to const char *. 
-*/
+#include "compare.hh"
 
+instantiate_compare(const String &, String::compare);
 
 // because const char* also has an operator ==, this is for safety:
-inline bool operator==(String s1, String s2){    return !(s1.compare(s2));}
-inline bool operator==(String s1, const char *s2){ return !(s1.compare(s2));}
-inline bool operator==(const char *s1, String s2){ return !(s2.compare(s1));}
-inline bool operator!=(String s1, const char *s2  ) {    return s1.compare(s2);}
-inline bool operator!=(const char *s1,String s2) {    return s2.compare(s1);}
-inline bool operator!=(String s1, String s2  ) {    return s1.compare(s2);}
+inline bool operator==(String s1, const char *s2){
+    return s1 == String(s2);
+}
+inline bool operator==(const char *s1, String s2)
+{
+    return String(s1)==s2;
+}
+inline bool operator!=(String s1, const char *s2  ) {
+    return s1!=String(s2);
+}
+inline bool operator!=(const char *s1,String s2) {
+    return String(s2) !=s1;
+}
+
 
 inline String
 operator  + (String s1, String  s2)