Changeset 1133


Ignore:
Timestamp:
Aug 8, 2003, 6:04:50 PM (17 years ago)
Author:
luba
Message:
  • Integer args are added
Location:
to-imperative/trunk/library/String
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/library/String/string_length.cc

    r1111 r1133  
    1616RF_FUNC (String_m_Length, (RF_ARG s_String), (RF_RES s_Len))
    1717  if (s_String.get_len() == 1) {
    18 
    1918    Term* p_String = s_String.get_first();
    2019    rftype::String* str = p_String->cast_to<rftype::String>(type_string);
    2120    if (str) {
    22       s_Len = Int32::create_expr(str->get_length());
     21      s_Len = Integer::create_expr(str->get_length());
    2322    }
    2423    else
  • to-imperative/trunk/library/String/string_ref.cc

    r1111 r1133  
    1717RF_FUNC (String_m_Ref, (RF_ARG s_String, s_Index), (RF_RES s_Char))
    1818  if (s_String.get_len() == 1) {
    19 
    2019    Term* p_String = s_String.get_first();
    2120    rftype::String* str = p_String->cast_to<rftype::String>(type_string);
     21    if (str)
     22    { 
     23      intptr_t ind = 0;
     24      Term* p_Index = s_Index.get_first();
     25      if (p_Index->get_type() == type_int) {
     26        Integer* Ind = static_cast<Integer*>(p_Index);
     27        intptr_t i = Ind->to_int();
     28        if (Ind->cmp(0) < 0 || uintptr_t(i) > SIZE_MAX)
     29          RF_LIB_ERROR("Invalid argument");
     30        else
     31          ind = i;
     32      }
     33      else
     34      if (p_Index->get_type() == type_int32)
     35      {
     36        intptr_t i = static_cast<Int32*>(p_Index)->to_int();
     37        if (i < 0 || uintptr_t(i) > SIZE_MAX)
     38          RF_LIB_ERROR("Invalid Argument");
     39        else
     40          ind = i;
     41      }
     42      else
     43        RF_LIB_ERROR("Invalid Argument");
    2244
    23     Term* p_Index = s_Index.get_first();
    24     rftype::Int32* Ind = p_Index->cast_to<rftype::Int32>(type_int32);
    25 
    26     if (str && Ind) {
    27       intptr_t ind = Ind->to_int();
    28       if (ind < 0)
    29         RF_LIB_ERROR("Invalid Argument");
    30       else {
    31         wchar_t const* content = str->get_data();
    32         rftype::String s = rftype::String(content);
    33         s_Char  = Char::create_expr(s[ind]);
    34       }
     45      wchar_t const* content = str->get_data();
     46      rftype::String s = rftype::String(content);
     47      s_Char  = Char::create_expr(s[ind]);
    3548    }
    36     else
    37       RF_LIB_ERROR("Invalid Argument");
    3849  }
    3950  else
Note: See TracChangeset for help on using the changeset viewer.