Back to index

texmacs  1.0.7.15
Functions | Variables
string.cpp File Reference
#include "string.hpp"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

Go to the source code of this file.

Functions

static int round_length (int n)
string copy (string s)
stringoperator<< (string &a, char x)
stringoperator<< (string &a, string b)
string operator* (string a, string b)
string operator* (const char *a, string b)
string operator* (string a, const char *b)
bool operator<= (string s1, string s2)
tm_ostreamoperator<< (tm_ostream &out, string a)
int hash (string s)
bool as_bool (string s)
int as_int (string s)
double as_double (string s)
char * as_charp (string s)
string as_string_bool (bool f)
string as_string (int i)
string as_string (unsigned int i)
string as_string (long int i)
string as_string (unsigned long int i)
string as_string (double x)
string as_string (const char *s)
bool is_bool (string s)
bool is_int (string s)
bool is_double (string s)
bool is_charp (string s)
bool is_quoted (string s)
bool is_id (string s)
void set_info_handler (void(*routine)(string, string, int))
void system_info (string message, string argument, int level)
void set_wait_handler (void(*routine)(string, string, int))
void system_wait (string message, string argument, int level)
void set_warning_handler (void(*routine)(string, string, int))
void system_warning (string message, string argument, int level)
void set_error_handler (void(*routine)(string, string, int))
void system_error (string message, string argument, int level)

Variables

static void(* the_info_handler )(string, string, int) = NULL
static void(* the_wait_handler )(string, string, int) = NULL
static void(* the_warning_handler )(string, string, int) = NULL
static void(* the_error_handler )(string, string, int) = NULL

Function Documentation

bool as_bool ( string  s)

Definition at line 198 of file string.cpp.

                   {
  return (s == "true");
}

Here is the caller graph for this function:

char* as_charp ( string  s)

Definition at line 233 of file string.cpp.

                    {
  int i, n= N(s);
  char *s2= tm_new_array<char> (n+1);
  for (i=0; i<n; i++) s2[i]=s[i];
  s2[n]= '\0';
  return s2;
}

Here is the call graph for this function:

double as_double ( string  s)

Definition at line 219 of file string.cpp.

                     {
  double x= 0.0;
  {
    int i, n= N(s);
    STACK_NEW_ARRAY (buf, char, n+1);
    for (i=0; i<n; i++) buf[i]=s[i];
    buf[n]='\0';
    sscanf (buf, "%lf", &x);
    STACK_DELETE_ARRAY (buf);
  } // in order to avoid segmentation fault due to compiler bug
  return x;
}

Here is the call graph for this function:

int as_int ( string  s)

Definition at line 203 of file string.cpp.

                  {
  int i=0, n=N(s), val=0;
  if (n==0) return 0;
  if (s[0]=='-') i++;
  while (i<n) {
    if (s[i]<'0') break;
    if (s[i]>'9') break;
    val *= 10;
    val += (int) (s[i]-'0');
    i++;
  }
  if (s[0]=='-') val=-val;
  return val;
}

Here is the call graph for this function:

string as_string ( int  i)

Definition at line 248 of file string.cpp.

                  {
  char buf[64];
  sprintf (buf, "%i", i);
  // sprintf (buf, "%i\0", i);
  return string (buf);
}
string as_string ( unsigned int  i)

Definition at line 256 of file string.cpp.

                           {
  char buf[64];
  sprintf (buf, "%i", i);
  // sprintf (buf, "%i\0", i);
  return string (buf);
}
string as_string ( long int  i)

Definition at line 264 of file string.cpp.

                       {
  char buf[64];
  sprintf (buf, "%li", i);
  // sprintf (buf, "%i\0", i);
  return string (buf);
}
string as_string ( unsigned long int  i)

Definition at line 272 of file string.cpp.

                                {
  char buf[64];
  sprintf (buf, "%li", i);
  // sprintf (buf, "%i\0", i);
  return string (buf);
}
string as_string ( double  x)

Definition at line 280 of file string.cpp.

                     {
  char buf[64];
  sprintf (buf, "%g", x);
  // sprintf (buf, "%g\0", x);
  return string(buf);
}
string as_string ( const char *  s)

Definition at line 288 of file string.cpp.

                          {
  return string (s);
}
string as_string_bool ( bool  f)

Definition at line 242 of file string.cpp.

                        {
  if (f) return string ("true");
  else return string ("false");
}

Here is the caller graph for this function:

string copy ( string  s)

Definition at line 123 of file string.cpp.

                {
  register int i, n=N(s);
  string r (n);
  for (i=0; i<n; i++) r[i]=s[i];
  return r;
}

Here is the call graph for this function:

int hash ( string  s)

Definition at line 184 of file string.cpp.

                {
  register int i, h=0, n=N(s);
  for (i=0; i<n; i++) {
    h=(h<<9)+(h>>23);
    h=h+((int) s[i]);
  }
  return h;
}

Here is the call graph for this function:

bool is_bool ( string  s)

Definition at line 293 of file string.cpp.

                   {
  return (s == "true") || (s == "false");
}

Here is the caller graph for this function:

bool is_charp ( string  s)

Definition at line 336 of file string.cpp.

                    { (void) s;
  return true;
}
bool is_double ( string  s)

Definition at line 310 of file string.cpp.

                     {
  int i=0, n=N(s);
  if (n==0) return false;
  if (s[i]=='+') i++;
  if (s[i]=='-') i++;
  if (i==n) return false;
  for (; i< n; i++)
    if ((s[i]<'0') || (s[i]>'9')) break;
  if (i==n) return true;
  if (s[i]=='.') {
    i++;
    if (i==n) return false;
    for (; i< n; i++)
      if ((s[i]<'0') || (s[i]>'9')) break;
  }
  if (i==n) return true;
  if (s[i++]!='e') return false;
  if (s[i]=='+') i++;
  if (s[i]=='-') i++;
  if (i==n) return false;
  for (; i< n; i++)
    if ((s[i]<'0') || (s[i]>'9')) return false;
  return true;
}

Here is the call graph for this function:

bool is_id ( string  s)

Definition at line 346 of file string.cpp.

                 {
  int i=0, n=N(s);
  if (n==0) return false;
  for (i=0; i< n; i++) {
    if ((i>0) && (s[i]>='0') && (s[i]<='9')) continue;
    if ((s[i]>='a') && (s[i]<='z')) continue;
    if ((s[i]>='A') && (s[i]<='Z')) continue;
    if (s[i]=='_') continue;
    return false;
  }
  return true;
}

Here is the call graph for this function:

bool is_int ( string  s)

Definition at line 298 of file string.cpp.

                  {
  int i=0, n=N(s);
  if (n==0) return false;
  if (s[i]=='+') i++;
  if (s[i]=='-') i++;
  if (i==n) return false;
  for (; i<n; i++)
    if ((s[i]<'0') || (s[i]>'9')) return false;
  return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_quoted ( string  s)

Definition at line 341 of file string.cpp.

                     {
  return (N(s)>=2) && (s[0]=='\042') && (s[N(s)-1]=='\042');
}

Here is the call graph for this function:

Here is the caller graph for this function:

string operator* ( string  a,
string  b 
)

Definition at line 146 of file string.cpp.

                                {
  register int i, n1=N(a), n2=N(b);
  string c(n1+n2);
  for (i=0; i<n1; i++) c[i]=a[i];
  for (i=0; i<n2; i++) c[i+n1]=b[i];
  return c;
}

Here is the call graph for this function:

string operator* ( const char *  a,
string  b 
)

Definition at line 155 of file string.cpp.

                                     {
  return string (a) * b;
}
string operator* ( string  a,
const char *  b 
)

Definition at line 160 of file string.cpp.

                                     {
  return a * string (b);
}
string& operator<< ( string a,
char  x 
)

Definition at line 131 of file string.cpp.

                                {
  a->resize (N(a)+ 1);
  a [N(a)-1]=x;
  return a;
}

Here is the call graph for this function:

string& operator<< ( string a,
string  b 
)

Definition at line 138 of file string.cpp.

                                  {
  register int i, k1= N(a), k2=N(b);
  a->resize (k1+k2);
  for (i=0; i<k2; i++) a[i+k1]= b[i];
  return a;
}

Here is the call graph for this function:

tm_ostream& operator<< ( tm_ostream out,
string  a 
)

Definition at line 176 of file string.cpp.

                                        {
  int i, n=N(a);
  if (n==0) return out;
  for (i=0; i<n; i++) out << a[i];
  return out;
}

Here is the call graph for this function:

bool operator<= ( string  s1,
string  s2 
)

Definition at line 165 of file string.cpp.

                                   {
  register int i;
  for (i=0; i<N(s1); i++) {
    if (i>=N(s2)) return false;
    if (s1[i]<s2[i]) return true;
    if (s2[i]<s1[i]) return false;
  }
  return true;
}

Here is the call graph for this function:

static int round_length ( int  n) [inline, static]

Definition at line 23 of file string.cpp.

                     {
  n=(n+3)&(0xfffffffc);
  if (n<24) return n;
  register int i=32;
  while (n>i) i<<=1;
  return i;
}

Here is the caller graph for this function:

void set_error_handler ( void(*)(string, string, int)  routine)

Definition at line 412 of file string.cpp.

                                                          {
  the_error_handler= routine; }
void set_info_handler ( void(*)(string, string, int)  routine)

Definition at line 369 of file string.cpp.

                                                         {
  the_info_handler= routine; }
void set_wait_handler ( void(*)(string, string, int)  routine)

Definition at line 381 of file string.cpp.

                                                         {
  the_wait_handler= routine; }

Here is the caller graph for this function:

void set_warning_handler ( void(*)(string, string, int)  routine)

Definition at line 400 of file string.cpp.

                                                            {
  the_warning_handler= routine; }
void system_error ( string  message,
string  argument,
int  level 
)

Definition at line 416 of file string.cpp.

                                                          {
  if (DEBUG_AUTO)
    cout << "TeXmacs] Error: " << message << " " << argument << LF;
  if (the_info_handler != NULL)
    the_info_handler ("Error: " * message, argument, level);
}

Here is the caller graph for this function:

void system_info ( string  message,
string  argument,
int  level 
)

Definition at line 373 of file string.cpp.

                                                         {
  if (DEBUG_AUTO)
    cout << "TeXmacs] " << message << " " << argument << LF;
  if (the_info_handler != NULL)
    the_info_handler (message, argument, level);
}

Here is the caller graph for this function:

void system_wait ( string  message,
string  argument,
int  level 
)

Definition at line 385 of file string.cpp.

                                                         {
  if (the_wait_handler == NULL) {
    if (DEBUG_AUTO) {
      if (message == "") cout << "TeXmacs] Done" << LF;
      else {
       if (argument == "") cout << "TeXmacs] " << message << LF;
       else cout << "TeXmacs] " << message << " " << argument << LF;
       cout << "TeXmacs] Please wait..." << LF;
      }
    }
  }
  else the_wait_handler (message, argument, level);
}

Here is the caller graph for this function:

void system_warning ( string  message,
string  argument,
int  level 
)

Definition at line 404 of file string.cpp.

                                                            {
  if (DEBUG_AUTO)
    cout << "TeXmacs] Warning: " << message << " " << argument << LF;
  if (the_info_handler != NULL)
    the_info_handler ("Warning: " * message, argument, level);
}

Here is the caller graph for this function:


Variable Documentation

void(* the_error_handler)(string, string, int) = NULL [static]

Definition at line 366 of file string.cpp.

void(* the_info_handler)(string, string, int) = NULL [static]

Definition at line 363 of file string.cpp.

void(* the_wait_handler)(string, string, int) = NULL [static]

Definition at line 364 of file string.cpp.

void(* the_warning_handler)(string, string, int) = NULL [static]

Definition at line 365 of file string.cpp.