CSpellNum Class Reference


Public Member Functions

void SpellNum (const char *p, char *buff_arg, char **bufc_arg)

Private Member Functions

void TwoDigits (const char *p)
void ThreeDigits (const char *p, int iBigOne)
void ManyDigits (int n, const char *p, bool bHundreds)
void FractionalDigits (int n, const char *p)
void StartWord (void)
void AddWord (const char *p)

Private Attributes

char * buff
char ** bufc
bool bNeedSpace

Detailed Description

Definition at line 2222 of file funmath.cpp.


Member Function Documentation

void CSpellNum::AddWord ( const char *  p  )  [private]

Definition at line 2250 of file funmath.cpp.

References safe_str.

Referenced by FractionalDigits(), ManyDigits(), SpellNum(), ThreeDigits(), and TwoDigits().

02251 {
02252     safe_str(p, buff, bufc);
02253 }

void CSpellNum::FractionalDigits ( int  n,
const char *  p 
) [private]

Definition at line 2370 of file funmath.cpp.

References AddWord(), ManyDigits(), mux_atoi64(), and StartWord().

Referenced by SpellNum().

02371 {
02372     ManyDigits(n, p, false);
02373     if (  0 < n
02374        && n < 15)
02375     {
02376         int d = n / 3;
02377         int r = n % 3;
02378         StartWord();
02379         if (r != 0)
02380         {
02381             AddWord(th_prefix[r]);
02382             if (d != 0)
02383             {
02384                 AddWord("-");
02385             }
02386         }
02387         AddWord(bigones[d]);
02388         AddWord("th");
02389         INT64 i64 = mux_atoi64(p);
02390         if (i64 != 1)
02391         {
02392             AddWord("s");
02393         }
02394     }
02395 }

void CSpellNum::ManyDigits ( int  n,
const char *  p,
bool  bHundreds 
) [private]

Definition at line 2321 of file funmath.cpp.

References AddWord(), StartWord(), ThreeDigits(), and TwoDigits().

Referenced by FractionalDigits(), and SpellNum().

02322 {
02323     // Handle special Hundreds cases.
02324     //
02325     if (  bHundreds
02326        && n == 4
02327        && p[1] != '0')
02328     {
02329         TwoDigits(p);
02330         StartWord();
02331         AddWord("hundred");
02332         TwoDigits(p+2);
02333         return;
02334     }
02335 
02336     // Handle normal cases.
02337     //
02338     int ndiv = ((n + 2) / 3) - 1;
02339     int nrem = n % 3;
02340     char buf[3];
02341     if (nrem == 0)
02342     {
02343         nrem = 3;
02344     }
02345 
02346     int j = nrem;
02347     for (int i = 2; 0 <= i; i--)
02348     {
02349         if (j)
02350         {
02351             j--;
02352             buf[i] = p[j];
02353         }
02354         else
02355         {
02356             buf[i] = '0';
02357         }
02358     }
02359     ThreeDigits(buf, ndiv);
02360     p += nrem;
02361     while (ndiv-- > 0)
02362     {
02363         ThreeDigits(p, ndiv);
02364         p += 3;
02365     }
02366 }

void CSpellNum::SpellNum ( const char *  p,
char *  buff_arg,
char **  bufc_arg 
)

Definition at line 2397 of file funmath.cpp.

References AddWord(), bNeedSpace, FractionalDigits(), ManyDigits(), mux_isdigit, mux_isspace, safe_str, and StartWord().

Referenced by FUNCTION().

02398 {
02399     buff = buff_arg;
02400     bufc = bufc_arg;
02401     bNeedSpace = false;
02402 
02403     // Trim Spaces from beginning.
02404     //
02405     while (mux_isspace(*number))
02406     {
02407         number++;
02408     }
02409 
02410     if (*number == '-')
02411     {
02412         StartWord();
02413         AddWord("negative");
02414         number++;
02415     }
02416 
02417     // Trim Zeroes from Beginning.
02418     //
02419     while (*number == '0')
02420     {
02421         number++;
02422     }
02423 
02424     const char *pA = number;
02425     while (mux_isdigit(*number))
02426     {
02427         number++;
02428     }
02429     size_t nA = number - pA;
02430 
02431     const char *pB  = NULL;
02432     size_t nB = 0;
02433     if (*number == '.')
02434     {
02435         number++;
02436         pB = number;
02437         while (mux_isdigit(*number))
02438         {
02439             number++;
02440         }
02441         nB = number - pB;
02442     }
02443 
02444     // Skip trailing spaces.
02445     //
02446     while (mux_isspace(*number))
02447     {
02448         number++;
02449     }
02450 
02451     if (  *number
02452        || nA >= 16
02453        || nB >= 15)
02454     {
02455         safe_str("#-1 ARGUMENT MUST BE A NUMBER", buff, bufc);
02456         return;
02457     }
02458 
02459     if (nA == 0)
02460     {
02461         if (nB == 0)
02462         {
02463             StartWord();
02464             AddWord("zero");
02465         }
02466     }
02467     else
02468     {
02469         ManyDigits(nA, pA, true);
02470         if (nB)
02471         {
02472             StartWord();
02473             AddWord("and");
02474         }
02475     }
02476     if (nB)
02477     {
02478         FractionalDigits(nB, pB);
02479     }
02480 }

void CSpellNum::StartWord ( void   )  [private]

Definition at line 2241 of file funmath.cpp.

References bNeedSpace, and safe_chr.

Referenced by FractionalDigits(), ManyDigits(), SpellNum(), ThreeDigits(), and TwoDigits().

02242 {
02243     if (bNeedSpace)
02244     {
02245         safe_chr(' ', buff, bufc);
02246     }
02247     bNeedSpace = true;
02248 }

void CSpellNum::ThreeDigits ( const char *  p,
int  iBigOne 
) [private]

Definition at line 2293 of file funmath.cpp.

References AddWord(), StartWord(), and TwoDigits().

Referenced by ManyDigits().

02294 {
02295     if (  p[0] == '0'
02296        && p[1] == '0'
02297        && p[2] == '0')
02298     {
02299         return;
02300     }
02301 
02302     // Handle hundreds.
02303     //
02304     if (p[0] != '0')
02305     {
02306         StartWord();
02307         AddWord(singles[p[0]-'0']);
02308         StartWord();
02309         AddWord("hundred");
02310     }
02311     TwoDigits(p+1);
02312     if (iBigOne > 0)
02313     {
02314         StartWord();
02315         AddWord(bigones[iBigOne]);
02316     }
02317 }

void CSpellNum::TwoDigits ( const char *  p  )  [private]

Definition at line 2257 of file funmath.cpp.

References AddWord(), and StartWord().

Referenced by ManyDigits(), and ThreeDigits().

02258 {
02259     int n0 = p[0] - '0';
02260     int n1 = p[1] - '0';
02261 
02262     if (n0 == 0)
02263     {
02264         if (n1 != 0)
02265         {
02266             StartWord();
02267             AddWord(singles[n1]);
02268         }
02269         return;
02270     }
02271     else if (n0 == 1)
02272     {
02273         StartWord();
02274         AddWord(teens[n1]);
02275         return;
02276     }
02277     if (n1 == 0)
02278     {
02279         StartWord();
02280         AddWord(tens[n0]);
02281     }
02282     else
02283     {
02284         StartWord();
02285         AddWord(tens[n0]);
02286         AddWord("-");
02287         AddWord(singles[n1]);
02288     }
02289 }


Field Documentation

bool CSpellNum::bNeedSpace [private]

Definition at line 2238 of file funmath.cpp.

Referenced by SpellNum(), and StartWord().

char** CSpellNum::bufc [private]

Definition at line 2237 of file funmath.cpp.

char* CSpellNum::buff [private]

Definition at line 2236 of file funmath.cpp.


The documentation for this class was generated from the following file:
Generated on Mon May 28 04:40:25 2007 for MUX by  doxygen 1.4.7