Beispiel #1
0
string consolidate(int x, string str) {
    string tmp, atmp;
    string *words;
    int i, y;

    if(x==1 || !str || str == "") return str;
    i = sizeof(words = explode(str, " "));
    if (words[i-1][0]=='(')
     {
      atmp = words[i-1];
      words[i-1]="";
      i -=1;
     }

    if((tmp = lower_case(words[0])) == "a" || tmp == "an" || tmp =="the")
      i = sizeof(words = words[1..i-1]);
    if((y=member_array("of", words))  > 0)
        words[y-1] = pluralize(words[y-1]);
    else words[i-1] =  pluralize(words[i-1]);
    tmp = cardinal(x)+" ";

if (atmp)
     return tmp+implode(words, " ")+" "+atmp;
   return tmp+implode(words, " ");
}
Beispiel #2
0
void pluralize_test() {
    NEW_TEST("pluralize");

    EQUAL_STR("cats", pluralize("cats"));
    EQUAL_STR("cats", pluralize("cat"));
    EQUAL_STR("babies", pluralize("baby"));
}
std::string ImageIO::getSummary() {
  std::ostringstream ss;
  int sum = 0;
  int recordSum = 0;
  for (auto const& volume: Volumes) {
    ss << "Volume " << volume->Name << ": processed "
       << pluralize("snapshot", volume->Snapshots.size()) << ", "
       << pluralize("record", volume->Count) << ".\n";
    sum += volume->Snapshots.size();
    recordSum += volume->Count;
  }
  ss << "Total: processed " << pluralize("volume", Volumes.size()) << ", "
     << pluralize("snapshot", sum) << ", "
     << pluralize("record", recordSum) << ".";
  return ss.str();
}
Beispiel #4
0
std::string
humanized_time_difference(time_t prev, time_t curr) {
    std::string ret = "";
    if (prev > curr) {
        std::swap(prev, curr);
    }

    if (prev == curr) {
        return "just now";
    }

    int sec = curr - prev;
    ret = uint_to_string(sec % 60, 2) + ret;

    int minute = sec / 60;
    ret = uint_to_string(minute % 60, 2) + ":" + ret;

    int hour = minute / 60;
    ret = uint_to_string(hour % 24, 2) + ":" + ret;

    int day = hour / 24;
    if (day) {
        ret = uint_to_string(day % 7) + pluralize(" day", day%7) + " " + ret;
    }

    int week = day / 7;
    if (week) {
        ret = uint_to_string(week % 4) + pluralize(" day", week%4) + " " + ret;
    }

    int month = week / 4;
    if (month) {
        ret = uint_to_string(month) + pluralize(" month", month) + " " + ret;
    }

    return ret;
}
Beispiel #5
0
//:FUNCTION number_of
//Handles the common operation: "0 bogs", "1 bog", "2 bogs", ...
//number_of(num, what)
string number_of(int num, string what) {
    if (num == 1) return "1 " + what;
    return num + " " + pluralize(what);
}
std::string format_verbose(AttrClass* attr)
{
    std::stringstream ss;
    // ss << attr->current_val << "/" << attr->max_val;
    ss << attr->max_val << "pts";
    std::string temp = ss.str();
    ss.str("");
    ss << colfg(AttrClass::attribute_color, temp) << " regen " << attr->regen_rate << pluralize(attr->regen_rate, "pt") << "/" << attr->regen_interval << "turn" << (attr->regen_interval > 1 ? "s" : "");
    return ss.str();
};