Ejemplo n.º 1
0
bool CAuthor::x_GetLabelV2(string* label, TLabelFlags flags, CTempString name,
                           CTempString initials, CTempString suffix)
{
    if (name.empty()) {
        return false;
    }

    if (name.size() <= 6  &&  (SWNC(name, "et al")  ||  SWNC(name, "et,al"))) {
        name = "et al.";
        if (NStr::EndsWith(*label, " and ")) {
            label->replace(label->size() - 5, NPOS, ", ");
        }
    }

    SIZE_TYPE pos = label->size();
    *label += name;
    if (HasText(initials)) {
        *label += ',';
        *label += initials;
    }
    if (HasText(suffix)) {
        *label += ' ';
        *label += suffix;
    }

    if ((flags & fLabel_FlatEMBL) != 0) {
        NStr::ReplaceInPlace(*label, ",", " ", pos);
    }

    return true;
}
Ejemplo n.º 2
0
bool CAuthor::GetLabelV2(string* label, TLabelFlags flags) const
{
    const CPerson_id& pid = GetName();
    switch (pid.Which()) {
    case CPerson_id::e_Name:
    {
        const CName_std& name = pid.GetName();
        if (HasText(name.GetLast())) {
            return x_GetLabelV2
                (label, flags, name.GetLast(),
                 name.CanGetInitials() ? name.GetInitials() : kEmptyStr,
                 name.CanGetSuffix() ? name.GetSuffix() : kEmptyStr);
        } else if (name.IsSetFull()  &&  HasText(name.GetFull())) {
            return x_GetLabelV2(label, flags, name.GetFull());
        } else {
            return false;
        }
    }
    case CPerson_id::e_Ml:
        return x_GetLabelV2(label, flags, pid.GetMl());
    case CPerson_id::e_Str:
        return x_GetLabelV2(label, flags, pid.GetStr()); 
    case CPerson_id::e_Consortium:
        return x_GetLabelV2(label, flags, pid.GetConsortium());
    default:
        return false;
    }
}
Ejemplo n.º 3
0
string ICitationBase::GetParenthesizedYear(const CDate& date)
{
    if (date.IsStd()) {
        string year;
        date.GetDate(&year, "(%4Y)");
        return year;
    } else if (date.IsStr()  &&  HasText(date.GetStr())
               &&  date.GetStr() != "?") {
        return '(' + date.GetStr().substr(0, 4) + ')';
    } else {
        return kEmptyStr;
    }
}
Ejemplo n.º 4
0
void ICitationBase::NoteSup(string* label, const CImprint& ip)
{
    _ASSERT(label != NULL);

    const string* issue     = ip.CanGetIssue()     ? &ip.GetIssue()     : NULL;
    const string* part_sup  = ip.CanGetPart_sup()  ? &ip.GetPart_sup()  : NULL;
    const string* part_supi = ip.CanGetPart_supi() ? &ip.GetPart_supi() : NULL;

    if (HasText(part_sup)) {
        MaybeAddSpace(label);
        *label += *part_sup;
    }
    if (HasText(issue)  ||  HasText(part_supi)) {
        MaybeAddSpace(label);
        *label += '(';
        if (HasText(issue)) {
            *label += *issue;
        }
        if (HasText(part_sup)) {
            *label += ' ' + *part_supi;
        }
        *label += ')';
    }
}
Ejemplo n.º 5
0
bool TBClipboard::GetText(TBStr &text)
{
    bool success = false;
    if (HasText() && OpenClipboard(NULL))
    {
        if (HANDLE hClipboardData = GetClipboardData(CF_UNICODETEXT))
        {
            wchar_t *pchData = (wchar_t*) GlobalLock(hClipboardData);
            int len = WideCharToMultiByte(CP_UTF8, 0, pchData, -1, NULL, 0, NULL, NULL);
            if (char *utf8 = new char[len])
            {
                WideCharToMultiByte(CP_UTF8, 0, pchData, -1, utf8, len, NULL, NULL);
                success = text.Set(utf8);
                delete [] utf8;
            }
            GlobalUnlock(hClipboardData);
        }
        CloseClipboard();
    }
    return success;
}
Ejemplo n.º 6
0
bool CCit_art::x_GetLabelV2(string* label, TLabelFlags flags,
                            const CCit_book& book)
{
    const CImprint& imp    = book.GetImp();
    int             prepub = imp.CanGetPrepub() ? imp.GetPrepub() : 0;
    string          year   = GetParenthesizedYear(imp.GetDate());

    MaybeAddSpace(label);

    if (prepub == CImprint::ePrepub_submitted
        ||  prepub == CImprint::ePrepub_other) {
        *label += "Unpublished " + year;
        return true;
    }

    string title = book.GetTitle().GetTitle();
    if (title.size() < 3) {
        *label += '.';
        return false;
    }

    *label += "(in) ";
    if (book.GetAuthors().GetLabel(label, flags, eLabel_V2)) {
        size_t n = book.GetAuthors().GetNameCount();
        if (n > 1) {
            *label += " (Eds.);";
        } else if (n == 1) {
            *label += " (Ed.);";
        }
        *label += '\n';
    }

    *label += NStr::ToUpper(title);

    const string* volume = imp.CanGetVolume() ? &imp.GetVolume() : NULL;
    if (HasText(volume)  &&  *volume != "0") {
        *label += ", Vol. " + *volume;
        if ((flags & fLabel_FlatNCBI) != 0) {
            NoteSup(label, imp);
        }
    }
    if (imp.CanGetPages()) {
        string pages = FixPages(imp.GetPages());
        if (HasText(pages)) {
            *label += ": " + pages;
        }
    }
    *label += ";\n";

    if (imp.CanGetPub()
        &&  imp.GetPub().GetLabel(label, flags, eLabel_V1)) { // sic
        // "V1" taken over by MakeAffilStr translation
        *label += ' ';
    }
    *label += year;

    if ((flags & fLabel_FlatNCBI) != 0
        &&  prepub == CImprint::ePrepub_in_press) {
        *label += " In press";
    }

    return true;
}
Ejemplo n.º 7
0
// Based on FormatCitGen from the C Toolkit's api/asn2gnb5.c.
bool CCit_gen::GetLabelV2(string* label, TLabelFlags flags) const
{
    if ( !CanGetCit()  &&  !CanGetJournal()  &&  !CanGetDate()
        &&  CanGetSerial_number() ) {
        return false;
    }

    if ( !CanGetJournal()  &&  CanGetCit()  &&  SWNC(GetCit(), "unpublished")) {
        if ((flags & fLabel_NoUnpubAffil) != 0) {
            MaybeAddSpace(label);
            *label += "Unpublished";
            return true;
        }

        if (CanGetAuthors()  &&  GetAuthors().CanGetAffil()) {
            MaybeAddSpace(label);
            *label += "Unpublished ";
            GetAuthors().GetAffil().GetLabel(label, flags, eLabel_V2);
            NStr::TruncateSpacesInPlace(*label, NStr::eTrunc_End);
            return true;
        }

        if (CanGetCit()  &&  HasText(GetCit())) {
            MaybeAddSpace(label);
            *label += NStr::TruncateSpaces(GetCit());
            return true;
        } else {
            return false;
        }
    }

    string year  = CanGetDate()  ? GetParenthesizedYear(GetDate()) : kEmptyStr;
    string pages = CanGetPages() ? FixPages(GetPages())            : kEmptyStr;
    string journal, inpress;
    SIZE_TYPE pos;

    if (CanGetJournal()) {
        journal = GetJournal().GetTitle();
    }

    if (CanGetCit()) {
        pos = GetCit().find("Journal=\"");
        if (pos != NPOS) {
            journal = GetCit().substr(pos + 9);
        } else if (SWNC(GetCit(), "submitted")
                   ||  SWNC(GetCit(), "unpublished")) {
            if ((flags & fLabel_NoBadCitGen) == 0  ||  !journal.empty()) {
                inpress = GetCit();
            } else {
                inpress = "Unpublished";
            }
        } else if (SWNC(GetCit(), "Online Publication")
                   ||  SWNC(GetCit(), "Published Only in DataBase")
                   ||  SWNC(GetCit(), "In press")) {
            inpress = GetCit();
        } else if (SWNC(GetCit(), "(er) ")) {
            journal = GetCit();
        } else if ((flags & fLabel_NoBadCitGen) == 0  &&  journal.empty()) {
            journal = GetCit();
        }
    }

    if ((!HasText(pages) || (flags & (fLabel_FlatNCBI | fLabel_FlatEMBL)) == 0)
        &&  journal.empty()  &&  !HasText(inpress)  &&  !HasText(year)
        &&  (!CanGetVolume() || !HasText(GetVolume()))) {
        return false;
    }

    string prefix;
    MaybeAddSpace(label);

    if ( !journal.empty() ) {
        pos = journal.find_first_of("=\"");
        if (pos != NPOS) {
            journal.resize(pos);
        }
        *label += journal;
        prefix = " ";
    }

    if (HasText(inpress)) {
        *label += prefix + inpress;
        prefix = " ";
    }

    if (CanGetVolume()  &&  HasText(GetVolume())) {
        *label += prefix + GetVolume();
    }

    if (HasText(pages)) {
        if ((flags & fLabel_FlatNCBI) != 0) {
            *label += ", " + pages;
        } else if ((flags & fLabel_FlatEMBL) != 0) {
            *label += ':' + pages;
        }
    }

    if (HasText(year)) {
        *label += ' ' + year;
    }

    return true;
}
Ejemplo n.º 8
0
// Based on FormatCitJour from the C Toolkit's api/asn2gnb5.c.
bool CCit_jour::GetLabelV2(string* label, TLabelFlags flags) const
{
    const CImprint& imp = GetImp();

    int prepub = imp.CanGetPrepub()    ? imp.GetPrepub()    : 0;
    int status = imp.CanGetPubstatus() ? imp.GetPubstatus() : 0;

    bool is_electronic = (status == ePubStatus_epublish
                          ||  status == ePubStatus_aheadofprint);

    const string* jtitle;
    try {
        jtitle = &GetTitle().GetTitle(CTitle::C_E::e_Iso_jta);
    } catch (CException&) {
        try {
            jtitle = &GetTitle().GetTitle();
            if (NStr::StartsWith(*jtitle, "(er)")) {
                is_electronic = true;
            }
            if ((flags & fLabel_ISO_JTA) != 0  &&  !is_electronic) {
                return false;
            }
        } catch (CException&) {
            jtitle = NULL;
        }
    }

    string year = GetParenthesizedYear(imp.GetDate());

    MaybeAddSpace(label);

    if (prepub == CImprint::ePrepub_submitted
        ||  prepub == CImprint::ePrepub_other) {
        *label += "Unpublished " + year;
        return true;
    }

    if (jtitle == NULL  ||  jtitle->size() < 3) {
        *label += '.';
        return false;
    }

    *label += *jtitle;

    const string* volume = imp.CanGetVolume() ? &imp.GetVolume() : NULL;
    string        pages  = imp.CanGetPages()  ? imp.GetPages()   : kEmptyStr;
    if ( !pages.empty()  &&  !is_electronic ) {
        pages = FixPages(pages);
    }

    if (HasText(volume)) {
        MaybeAddSpace(label);
        *label += *volume;
    }

    if ((flags & fLabel_FlatNCBI) != 0
        &&  (HasText(volume)  ||  HasText(pages))) {
        NoteSup(label, imp);
    }

    if ((flags & fLabel_FlatNCBI) != 0) {
        if (HasText(pages)) {
            *label += ", " + pages;
        }
    } else if ((flags & fLabel_FlatEMBL) != 0) {
        if (HasText(pages)) {
            *label += ':' + pages;
        } else if (prepub == CImprint::ePrepub_in_press  ||  !HasText(volume)) {
            MaybeAddSpace(label);
            *label += "0:0-0";
        }
    }

    *label += ' ' + year;
    
    if ((flags & fLabel_FlatNCBI) != 0) {
        if (prepub == CImprint::ePrepub_in_press
            ||  (status == ePubStatus_aheadofprint  &&  !HasText(pages))) {
            MaybeAddSpace(label);
            *label += "In press";
        }
    }

    return true;
}