NCBI C++ ToolKit
Name_std.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: Name_std.cpp 73865 2016-07-28 17:21:31Z bollin $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: .......
27  *
28  * File Description:
29  * .......
30  *
31  * Remark:
32  * This code was originally generated by application DATATOOL
33  * using the following specifications:
34  * 'general.asn'.
35  */
36 
37 // standard includes
38 #include <ncbi_pch.hpp>
39 
40 // generated includes
42 
43 // generated classes
44 
46 
47 BEGIN_objects_SCOPE // namespace ncbi::objects::
48 
49 // destructor
51 {
52 }
53 
54 
56 {
57  static const char* sfxs[] = { "2nd", "3rd", "4th", "5th", "6th", "II", "III", "IV", "Jr.", "Sr.", "V", "VI"};
59 
60  return suffixes;
61 }
62 
63 
65 {
66  if ((IsSetSuffix() && !NStr::IsBlank(GetSuffix()))
67  || !IsSetLast()) {
68  // bail if already have non-empty suffix or if no last name
69  return false;
70  }
71  string& last = SetLast();
72  size_t pos = NStr::Find(last, " ");
73  if (pos == string::npos) {
74  return false;
75  }
76  size_t npos = NStr::Find(last, " ", pos + 1);
77  while (npos != string::npos) {
78  pos = npos;
79  npos = NStr::Find(last, " ", pos + 1);
80  }
81 
82  string suffix = last.substr(pos + 1);
83  if (NStr::Equal(suffix, "Jr.") ||
84  NStr::Equal(suffix, "Jr") ||
85  NStr::Equal(suffix, "Sr.") ||
86  NStr::Equal(suffix, "Sr") ||
87  NStr::Equal(suffix, "II") ||
88  NStr::Equal(suffix, "III") ||
89  NStr::Equal(suffix, "IV")) {
92  last = last.substr(0, pos);
93  return true;
94  }
95  return false;
96 }
97 
98 
100 {
101  // remove spaces
102  NStr::ReplaceInPlace(suffix, " ", "");
103 
104  if (!suffix.empty()) {
105  // remove any period, if any, on the end
106  if (NStr::EndsWith(suffix, ".")) {
107  suffix.resize(suffix.length() - 1);
108  }
109 
110  if (NStr::EqualNocase(suffix, "1d")) {
111  suffix = "1st";
112  } else if (NStr::EqualNocase(suffix, "2d")) {
113  suffix = "2nd";
114  } else if (NStr::EqualNocase(suffix, "3d")) {
115  suffix = "3rd";
116  } else if (NStr::EqualNocase(suffix, "Sr")) {
117  suffix = "Sr.";
118  } else if (NStr::EqualNocase(suffix, "Jr")) {
119  suffix = "Jr.";
120  }
121  }
122 }
123 
124 
125 END_objects_SCOPE // namespace ncbi::objects::
126 
128 
129 /* Original file checksum: lines: 65, chars: 1888, CRC32: daed53d2 */
bool ExtractSuffixFromLastName()
Definition: Name_std.cpp:64
static const TSuffixes & GetStandardSuffixes(void)
Get a list of NCBI's standard suffixes.
Definition: Name_std.cpp:55
static void FixSuffix(string &suffix)
Definition: Name_std.cpp:99
~CName_std(void)
destructor
Definition: Name_std.cpp:50
static DLIST_TYPE *DLIST_NAME() last(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:51
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static bool EndsWith(const CTempString str, const CTempString end, ECase use_case=eCase)
Check if a string ends with a specified suffix value.
Definition: ncbistr.hpp:5430
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
static SIZE_TYPE Find(const CTempString str, const CTempString pattern, ECase use_case=eCase, EDirection direction=eForwardSearch, SIZE_TYPE occurrence=0)
Find the pattern in the string.
Definition: ncbistr.cpp:2891
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
Definition: ncbistr.hpp:5353
static bool Equal(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2, ECase use_case=eCase)
Test for equality of a substring with another string.
Definition: ncbistr.hpp:5384
static string & ReplaceInPlace(string &src, const string &search, const string &replace, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
Definition: ncbistr.cpp:3405
bool IsSetSuffix(void) const
Jr, Sr, III Check if a value has been assigned to Suffix data member.
Definition: Name_std_.hpp:645
bool IsSetLast(void) const
Check if a value has been assigned to Last data member.
Definition: Name_std_.hpp:410
const TSuffix & GetSuffix(void) const
Get the Suffix member data.
Definition: Name_std_.hpp:657
TSuffix & SetSuffix(void)
Assign a value to Suffix data member.
Definition: Name_std_.hpp:680
TLast & SetLast(void)
Assign a value to Last data member.
Definition: Name_std_.hpp:445
static const char * suffix[]
Definition: pcregrep.c:408
#define DEFINE_STATIC_ARRAY_MAP_WITH_COPY(Type, Var, Array)
Definition: static_set.hpp:894
Modified on Tue Apr 16 20:14:04 2024 by modify_doxy.py rev. 669887