예제 #1
0
var Real_Eq(var self, var other) {
  RealData* ro = cast(self, Real);
  if (type_implements(type_of(other), AsDouble)) {
    return (var)(intptr_t)(ro->value == as_double(other));
  } else {
    return False;
  }
}
예제 #2
0
var Int_Eq(var self, var other) {
  IntData* io = cast(self, Int);
  if (type_implements(type_of(other), AsLong)) {
    return (var)(intptr_t)(io->value == as_long(other));
  } else {
    return False;
  }
}
예제 #3
0
var String_Eq(var self, var other) {
  StringData* fst = cast(self, String);
  if (type_implements(type_of(other), AsStr)) {
    return (var)(intptr_t)(strcmp(fst->value, as_str(other)) == 0);
  } else {
    return False;
  }
}
예제 #4
0
int show_to(var self, var out, int pos) {
  
  if (not type_implements(type_of(self), Show)) {
    return print_to(out, 0, "<'%s' At 0x%p>", type_of(self), self);
  } else {
    Show* ishow = type_class(type_of(self), Show);
    return ishow->show(self, out, pos);
  }
  
}
예제 #5
0
void String_Discard(var self, var obj) {
  StringData* s = cast(self, String);
  
  if (type_implements(type_of(obj), AsStr)) {
    const char* ostr = as_str(obj);
    const char* pos = strstr(s->value, ostr);
    
    int bytecount = strlen(s->value) - strlen(pos) - strlen(ostr) + 1;
    memmove((char*)pos, pos + strlen(ostr), bytecount);
  }
  
  if (type_implements(type_of(obj), AsChar)) {
    char ochar = as_char(obj);
    const char* pos = strchr(s->value, ochar);
    while(pos != NULL) {
      pos = pos+1;
    }
  }
  
}
예제 #6
0
var String_Contains(var self, var obj) {
  StringData* s = cast(self, String);
  
  if (type_implements(type_of(obj), AsStr)) {
    const char* ostr = as_str(obj);
    if ( strstr(s->value, ostr) ) {
      return True;
    } else {
      return False;
    }
  }
  
  if (type_implements(type_of(obj), AsChar)) {
    char ochar = as_char(obj);
    if (strchr(s->value, ochar)) {
      return True;
    } else {
     return False;
    }
  }
  
  return False;
}
예제 #7
0
var String_Lt(var self, var obj) {
  StringData* s = cast(self, String);
  if (not type_implements(type_of(obj), AsStr)) return false;
  
  const char* fst = s->value;
  const char* snd = as_str(obj);
  
  int fstlen = strlen(fst);
  int sndlen = strlen(snd);
  int minlen = fstlen > sndlen ? sndlen : fstlen; 
  
  for(int i = 0; i < minlen; i++) {
    if (fst[i] < snd[i]) return True;
  }
  
  if (fstlen < sndlen) return True;
  
  return False;
}