string generateabbr(string s) { int len = s.size(); string re; if (len <= 2) return s; re.push_back(s[0]); re = re + to_String(len-2); re.push_back(s[len-1]); return re; }
void print_object(FILE *fp, UnionType o) { if (!fp) fp = stdout; //fprintf(stderr, "type = [%d]\n", TYPE(o)); switch (TYPE(o.o)) { case Int: fprintf(fp, "%d", (int)to_Int(o.o)); break; case Double: fprintf(fp, "%f", o.d); break; case String: fprintf(fp, "%s", (to_String(o.o))->s); break; case Array: if (fp != stdout) { _print_with_handler(fp, to_Array(o.o)); } else { print(to_Array(o.o)); } break; case ArrayRef: fprintf(fp, "ARRAY(%p)", to_Ptr(o.o)); break; case Hash: print_hash(fp, to_Hash(o.o)); break; case HashRef: fprintf(fp, "HASH(%p)", to_Ptr(o.o)); break; case CodeRef: fprintf(fp, "CODE(%p)", to_Ptr(o.o)); break; case ObjectType: { Object *object = to_Object(o.o); print_object(fp, object->v); break; } case BlessedObjectType: fprintf(fp, "%s=HASH(%p)", (to_BlessedObject(o.o))->pkg_name, to_Ptr(o.o)); break; default: break; } }
// ------------------------------------------------------------------ vaca::String FileReader::readLine(const std::u32string& delim) { char32_t decChar; size_t countDelim = delim.length(); size_t equalChar = 0; std::u32string tmp; if (countDelim) while (readChar(decChar)) { if (decChar == delim[equalChar]) { ++equalChar; if (countDelim == equalChar) break; } else { tmp.push_back(decChar); } } return to_String(tmp); }