Ignore:
Timestamp:
May 28, 2003, 9:16:27 AM (18 years ago)
Author:
luba
Message:
  • is_number() method is corrected;
  • has_spaces() method is added;
File:
1 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/runtime/rf_word.ih

    r762 r773  
    9595//
    9696
     97enum is_number_res {plus, minus, positive_number, not_a_number};
     98
    9799inline int Word::is_number () const
    98100{
    99   int res = 0;
     101  enum is_number_res res = not_a_number;
    100102  size_t i = 0;
    101103  Header* h = static_cast<Header*>(ptr_data2);
    102104
    103105  for (; ;)
    104     if ((h->content[i]) != ' ')
     106    if (((h->content[i]) != ' '))
    105107      break;
    106108    else
    107109      i++;
    108110   
    109   if ((h->content[i]) == '-') res = -1;
    110   if ((h->content[i]) == '+') res = 1;
    111   if (iswdigit(h->content[i])) res = 2;
     111  if ((h->content[i]) == '-') res = minus;
     112  if ((h->content[i]) == '+') res = plus;
     113  if (iswdigit(h->content[i])) res = positive_number;
    112114 
    113   if (res)
     115  if (res != not_a_number)
    114116    i++;
    115117
     
    124126
    125127      else {
    126         res = 0;
     128        res = not_a_number;
    127129        break;
    128130      }
     
    130132    else
    131133      if (prev) {
    132         res = 0;
     134        res = not_a_number;
    133135        break;
    134136      }
     
    139141  return res;
    140142}
     143
     144
     145//the method returns 1, if the word has spaces at the beginning,
     146//and returns 2, if the word has spaces at the end
     147//
     148inline int Word::has_space () const {
     149  Header* h = static_cast<Header*>(ptr_data2);
     150  if ( *(h->content) == ' ')
     151    return 1;
     152  else
     153  if ( *(h->content + h->length) == ' ')
     154    return 2;
     155
     156}
     157
     158
    141159
    142160//the method is called only if is_number() function
Note: See TracChangeset for help on using the changeset viewer.