Exemple #1
0
static void TestIconv(const Stroka& utf8, const Stroka& other, ECharset enc) {
    Wtroka wide0 = CharToWide(utf8, CODES_UTF8);
    Wtroka wide1 = CharToWide(other, enc);

    UNIT_ASSERT(wide0 == wide1);

    Stroka temp = WideToChar(wide0, CODES_UTF8);
    UNIT_ASSERT(temp == utf8);

    temp = WideToChar(wide0, enc);
    UNIT_ASSERT(temp == other);

    temp = Recode(enc, CODES_UTF8, other);
    UNIT_ASSERT(temp == utf8);

    temp = Recode(CODES_UTF8, enc, utf8);
    UNIT_ASSERT(temp == other);

    size_t read = 0;
    size_t written = 0;

    RECODE_RESULT res = RecodeToUnicode(enc, other.c_str(), wide1.begin(), other.size(), wide1.size(), read, written);
    UNIT_ASSERT(res == RECODE_OK);
    UNIT_ASSERT(read == other.size());
    UNIT_ASSERT(written == wide1.size());
    UNIT_ASSERT(wide0 == wide1);

    res = RecodeFromUnicode(enc, wide0.c_str(), temp.begin(), wide0.size(), temp.size(), read, written);
    UNIT_ASSERT(res == RECODE_OK);
    UNIT_ASSERT(read == wide0.size());
    UNIT_ASSERT(written == other.size());
    UNIT_ASSERT(temp == other);
}
Exemple #2
0
 size_t TFormatOutput::FormLine(const char *str, size_t pos, Stroka &Line) {
     Line = "";
     size_t len = strlen(str);
     for(size_t i = 0; i < Level; i++)
         Line += Ident;
     int NextLine;
     size_t pos1 = pos;
     while(1) {
         pos1 = skipspace(str, pos1, len, NextLine, Line);
         if(NextLine || Line.size() >= MaxLen || pos1 >= len)
             return pos1;
         pos1 = skipword(str, pos1, len, NextLine, Line);
         if(NextLine || Line.size() >= MaxLen || pos1 >= len)
             return pos1;
     }
 }
// Like Stroka::Quote(), but does not quote digits-only string
static Stroka QuoteForHelp(const Stroka& str) {
    if (str.empty())
        return str.Quote();
    for (size_t i = 0; i < str.size(); ++i) {
        if (!isdigit(str[i]))
            return str.Quote();
    }
    return str;
}
Exemple #4
0
void CHomonym::Print(TOutputStream& stream, const Stroka& strKwType, ECharset encoding) const
{
    Stroka s;
    if (strKwType.size())
        s = Substitute(" (<b>$0</b>) ", strKwType);

    stream << "  " << NStr::Encode(GetShortLemma(), encoding) << " ";
    PrintFormGrammems(stream, encoding);
    stream << s << GetLabelsString(encoding) << Endl;
}
bool TOpt::IsAllowedLongName(const Stroka& name, unsigned char* out) {
    for (size_t i = 0; i != name.size(); ++i) {
        const unsigned char c = name[i];
        if (!isprint(c) || TStringBuf::npos != ExcludedLongNameChars.find(c)) {
            if (NULL != out)
                *out = c;
            return false;
        }
    }
    return true;
}
Exemple #6
0
Wtroka CProcessor::GetInterviewFio(Stroka strUrl) const
{
    ymap<Stroka, Wtroka>::const_iterator it = InterviewUrl2Fio.find(strUrl);
    if (it != InterviewUrl2Fio.end())
        return it->second;
    static const Stroka kHTTP = "http://";
    if (strUrl.has_prefix(kHTTP)) {
        strUrl = strUrl.substr(kHTTP.size());
        return GetInterviewFio(strUrl);
    }
    return Wtroka();
}
Exemple #7
0
void CHomonym::Print(TOutputStream& stream, ECharset encoding) const
{
    Stroka s;
    s = GetStrKWType(encoding);
    if (s.size())
        s = Substitute(" (<b>$0</b>) ", s);

    if (IsDeleted())
        s += "[deleted]";
    stream << NStr::Encode(GetShortLemma(), encoding) << " ";
    PrintGrammems(Grammems.All(), stream, encoding);
    stream << s << GetLabelsString(encoding);
}
Stroka CCommonParm::GetPrettyOutputFileName() const {
    if (NULL != Config.Get() && Config->has_prettyoutput()) {
        Stroka fn = Config->GetPrettyOutput();
        fn.to_lower();
        if ("stdout" == fn || "stderr" == fn)
            return fn;
        if ("-" == fn)
            return "stdout";
        if (fn.size() > 0)
            return Config->GetPrettyOutput();
    }

    return Stroka("");
}
// read length-value (throws yexception or TLoadEOF)
void CStdinMapReduceDocsReader::ReadLV(TInputStream& is, Stroka& value)
{
    ::Load(&is, value);
    if (value.size() == 0 || value.size() > (1 << 27))
        ythrow yexception() << "bad data size wile reading MapReduce length-value output (" << value.size() << " bytes)";
}