MCPcopy Create free account
hub / github.com/data61/MP-SPDZ / CmpOptStringPtr

Function CmpOptStringPtr

Tools/ezOptionParser.h:83–120  ·  view source on GitHub ↗

################################################################### */ Compare strings for opts, so short opt flags come before long format flags. For example, -d < --dimension < --dmn, and also lower come before upper. The default STL std::string compare doesn't do that. */

Source from the content-addressed store, hash-verified

81For example, -d < --dimension < --dmn, and also lower come before upper. The default STL std::string compare doesn't do that.
82*/
83static bool CmpOptStringPtr(std::string * s1, std::string * s2) {
84 int c1,c2;
85 const char *s=s1->c_str();
86 for(c1=0; c1 < (long int)s1->size(); ++c1)
87 if (isalnum(s[c1])) // locale sensitive.
88 break;
89
90 s=s2->c_str();
91 for(c2=0; c2 < (long int)s2->size(); ++c2)
92 if (isalnum(s[c2]))
93 break;
94
95 // Test which has more symbols before its name.
96 if (c1 > c2)
97 return false;
98 else if (c1 < c2)
99 return true;
100
101 // Both have same number of symbols, so compare first letter.
102 char char1 = s1->at(c1);
103 char char2 = s2->at(c2);
104 char lo1 = tolower(char1);
105 char lo2 = tolower(char2);
106
107 if (lo1 != lo2)
108 return lo1 < lo2;
109
110 // Their case doesn't match, so find which is lower.
111 char up1 = isupper(char1);
112 char up2 = isupper(char2);
113
114 if (up1 && !up2)
115 return false;
116 else if (!up1 && up2)
117 return true;
118
119 return (s1->compare(*s2)<0);
120};
121/* ################################################################### */
122/*
123Makes a vector of strings from one string,

Callers

nothing calls this directly

Calls 2

compareMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected