本文整理汇总了C++中TChA::CStr方法的典型用法代码示例。如果您正苦于以下问题:C++ TChA::CStr方法的具体用法?C++ TChA::CStr怎么用?C++ TChA::CStr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TChA
的用法示例。
在下文中一共展示了TChA::CStr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetNthOccurence
int GetNthOccurence(const TChA& Url, const int& Count, const char Ch='/') {
const char *c = Url.CStr();
int cnt = 0;
while (*c && cnt != Count) {
if (*c == Ch) { cnt++; }
c++;
}
return int(c-Url.CStr()-1);
}
示例2: SplitWords
int TStrUtil::SplitWords(TChA& ChA, TVec<char *>& WrdV, const bool& SplitOnWs) {
WrdV.Clr(false);
WrdV.Add(ChA.CStr());
for (char *c = (char *) ChA.CStr(); *c; c++) {
if ((SplitOnWs && *c == ' ') || (! SplitOnWs && ! TCh::IsAlNum(*c))) {
*c = 0;
if (! WrdV.Empty() && strlen(WrdV.Last()) == 0) { WrdV.DelLast(); }
WrdV.Add(c+1);
}
}
return WrdV.Len();
}
示例3: SplitOnCh
int TStrUtil::SplitOnCh(TChA& ChA, TVec<char *>& WrdV, const char& Ch, const bool& SkipEmpty) {
WrdV.Clr(false);
WrdV.Add(ChA.CStr());
for (char *c = (char *) ChA.CStr(); *c; c++) {
if (*c == Ch) {
*c = 0;
if (SkipEmpty && ! WrdV.Empty() && strlen(WrdV.Last()) == 0) { WrdV.DelLast(); }
WrdV.Add(c+1);
}
}
if (SkipEmpty && ! WrdV.Empty() && strlen(WrdV.Last()) == 0) { WrdV.DelLast(); }
return WrdV.Len();
}
示例4: GetCleanStr
// space seprated sequence of words (includes all non-blank characters, i.e., punctuations)
TChA TStrUtil::GetCleanStr(const TChA& ChA) {
char *b = (char *) ChA.CStr();
while (*b && ! TCh::IsAlNum(*b)) {
b++;
}
if (*b == 0) {
return TChA();
}
TChA OutChA(ChA.Len());
char *e = b;
bool ws=false;
while (*e) {
while (*e && TCh::IsWs(*e)) {
e++;
ws=true;
}
if (! *e) {
break;
}
if (ws) {
OutChA.AddCh(' ');
ws=false;
}
OutChA.AddCh(*e);
e++;
}
//OutChA.ToLc();
return OutChA;
}
示例5: GetCleanWrdStr
// space separated sequence of words, remove all punctuations, etc.
TChA TStrUtil::GetCleanWrdStr(const TChA& ChA) {
char *b = (char *) ChA.CStr();
while (*b && ! TCh::IsAlNum(*b)) {
b++;
}
if (*b == 0) {
return TChA();
}
TChA OutChA(ChA.Len());
char *e = b, tmp;
while (*e) {
b = e;
while (*e && (TCh::IsAlNum(*e) || ((*e=='\'' || *e=='-') && TCh::IsAlNum(*(e+1))))) {
e++;
}
if (b < e) {
tmp = *e;
*e=0;
OutChA += b;
OutChA.AddCh(' ');
*e = tmp;
}
while (*e && ! TCh::IsAlNum(*e)) {
e++;
}
if (! *e) {
break;
}
}
OutChA.DelLastCh();
OutChA.ToLc();
return OutChA;
}
示例6: DumpStr
const char* TSsParserMP::DumpStr() const {
static TChA ChA(10*1024);
ChA.Clr();
for (int i = 0; i < FldV.Len(); i++) {
ChA += TStr::Fmt(" %d: '%s'\n", i, FldV[i]);
}
return ChA.CStr();
}
示例7: readLine
void TNodeJsFIn::readLine(const v8::FunctionCallbackInfo<v8::Value>& Args) {
v8::Isolate* Isolate = v8::Isolate::GetCurrent();
v8::HandleScope HandleScope(Isolate);
TNodeJsFIn* JsFIn = ObjectWrap::Unwrap<TNodeJsFIn>(Args.This());
TChA LnChA; JsFIn->SIn->GetNextLnBf(LnChA);
Args.GetReturnValue().Set(v8::String::NewFromUtf8(Isolate, LnChA.CStr()));
}
示例8: StemX
TStr TPorterStemmer::StemX(const TStr& s){
TChA buf = s; buf.ToUc();
int len = buf.Len(); char *p = buf.CStr();
if (len > 1 && p[len - 1] == 'S' && p[len - 2] == '\'')
p[len - 2] = '\0';
else if (len > 0 && p[len - 1] == '\'')
p[len - 1] = '\0';
return StemInPlace(p);
}
示例9: IsLatinStr
bool TStrUtil::IsLatinStr(const TChA& Str, const double& MinAlFrac) {
int AlNumCnt=0, ChCnt=0;
for (const char *c = Str.CStr(); *c; c++) {
if (TCh::IsWs(*c)) { continue; }
if (*c > 0 && TCh::IsAlNum(*c)) { AlNumCnt++; }
ChCnt++;
}
if (double(AlNumCnt)/double(ChCnt) > MinAlFrac) { return true; }
return false;
}
示例10: SplitLines
int TStrUtil::SplitLines(TChA& ChA, TVec<char *>& LineV, const bool& SkipEmpty) {
LineV.Clr(false);
LineV.Add(ChA.CStr());
bool IsChs=false;
for (char *c = (char *) ChA.CStr(); *c; c++) {
if (*c == '\n') {
if (c > ChA.CStr() && *(c-1)=='\r') { *(c-1)=0; } // \r\n
*c=0;
if (SkipEmpty) {
if (IsChs) { LineV.Add(c+1); }
} else {
LineV.Add(c+1);
}
IsChs=false;
} else {
IsChs=true;
}
}
return LineV.Len();
}
示例11: RemoveHtmlTags
void TStrUtil::RemoveHtmlTags(const TChA& HtmlStr, TChA& TextStr) {
TextStr.Clr();
char *StrB, *StrE;
// use full page html: skip till <body>
//PageHtmlStr = "<script fdsfs> fsdfsd </script> jure";
/*if (UseFullHtml) {
StrB = PageHtmlStr.CStr();
StrE = StrB+PageHtmlStr.Len();
char * NewB = strstr(StrB, "<body>");
if (NewB != NULL) { StrB = NewB+6; }
char * NewE = strstr(StrB, "body>");
if (NewE != NULL) {
while (true) {
char *E=strstr(NewE+4, "body>");
if (E == NULL) { break; } NewE = E; }
StrE = NewE;
}
} else { // only extracted post html*/
StrB = (char *) HtmlStr.CStr();
StrE = (char *) StrB+HtmlStr.Len(); //}
for (char *e = StrB; e < StrE; ) {
char* b = e;
while (e<StrE && *e != '<') { e++; }
// copy text
char tmp=*e; *e = 0;
TextStr+= b; TextStr.AddCh(' '); *e = tmp;
if (e >= StrE) { return; }
// if start of a comment: skip
if (e[1]=='!' && e[2]=='-' && e[3]=='-') { // comment
e += 3;
while(e<StrE && !(*(e-2)=='-' && *(e-1)=='-' && *e=='>')) { e++; }
e++; continue;
}
// if "<script" then skip
if (e[1]=='s' && e[2]=='c' && e[3]=='r' && e[4]=='i' && e[5]=='p' && e[6]=='t') {
e += 5;
while(e<StrE && !(*(e-6)=='s' && *(e-5)=='c' && *(e-4)=='r' && *(e-3)=='i' && *(e-2)=='p' && *(e-1)=='t' && *e=='>')) { e++; }
e++; continue;
}
// skip to end of tag
while (e < StrE && *e != '>') { e++; }
if (e>=StrE) { return; }
e++;
}
}
示例12: SplitSentences
int TStrUtil::SplitSentences(TChA& ChA, TVec<char *>& SentenceV) {
SentenceV.Clr();
const char *B = ChA.CStr();
const char *E = B+ChA.Len();
char *c = (char *) B;
while (*c && TCh::IsWs(*c)) { c++; }
if (*c) { SentenceV.Add(c); } else { return 0; }
for (; c < E; c++) {
if (c<E && (*c == '.' || *c == '!' || *c == '?') && ! TCh::IsAlNum(*(c+1))) { // end of sentence
if (c<E && *(c+1)=='"') { *c='"'; c++; } // blah." --> blah"
if (c>=E) { continue; }
*c=0; c++;
char *e = c-1;
while (e>B && *e!='"' && ! TCh::IsAlNum(*e)) { *e=0; e--; } // skip trailing non-alpha-num chars
while (c<E && ! (TCh::IsAlNum(*c) || (*c=='"' && TCh::IsAlNum(*(c+1))))) { c++; } // sentence starts with AlNum or "AlNum
if (c<E) { SentenceV.Add(c); }
}
}
return SentenceV.Len();
}
示例13: if
// get <TagNm>*</TagNm> (can be many tags inbetween
bool TStrUtil::GetXmlTagNmVal2(TXmlLx& XmlLx, TChA& TagNm, TChA& TagVal, const bool& TakeTagNms) {
if (XmlLx.GetSym() != xsySTag) {
return false; }
TagVal.Clr();
TagNm = XmlLx.TagNm;
//const TXmlLxSym NextSym = XmlLx.GetSym();
while (XmlLx.Sym != xsyETag || XmlLx.TagNm != TagNm.CStr()) {
if (TakeTagNms) {
TagVal += XmlLx.TxtChA; }
else if (XmlLx.Sym == xsyStr) {
TagVal += XmlLx.TxtChA; }
XmlLx.GetSym();
}
return true;
//if (NextSym == xsyStr) {
// EAssertR(XmlLx.GetSym() == xsyETag, TagNm);
//} else {
// EAssertR(NextSym == xsyETag, TagNm); // empty tag
//printf(" token: %s empty! %s\n", XmlLx.TagNm.CStr(), XmlLx.GetFPosStr().CStr());
//}
}
示例14: GetDtTmFromStr
// Parse strings of the form 2006-08-28 14:11:16 or 14:11:16 08/28/2008
// Non-numeric characters act as separators (there can be many consecutive separating characters)
// Variables give indexes of the date fields
TSecTm TSecTm::GetDtTmFromStr(const TChA& YmdHmsPmStr, const int& YearId, const int& MonId,
const int& DayId, const int& HourId, const int& MinId, const int& SecId) {
TChA Tmp = YmdHmsPmStr;
TVec<char *> FldV;
// get the sequences of numbers
for (char *c = (char *) Tmp.CStr(); *c; c++) {
if (TCh::IsNum(*c)) {
FldV.Add(c);
while (TCh::IsNum(*c)) { c++; }
c--;
} else { *c = 0; }
}
const int Y = atoi(FldV[YearId]);
const int M = atoi(FldV[MonId]);
const int D = atoi(FldV[DayId]);
const int H = atoi(FldV[HourId]);
const int m = atoi(FldV[MinId]);
const int S = atoi(FldV[SecId]);
IAssert(Y>0 && M>0 && D>0 && M<13 && D<32);
IAssert(H>=0 && H<24 && m>=0 && m<60 && S>=0 && S<60);
return TSecTm(Y,M,D,H,m,S);
}
示例15: Sentencize
///////////////////////////////
// Tokenizer-Utils
void TTokenizerUtil::Sentencize(const PSIn& SIn, TStrV& Sentences, const bool& SplitNewLineP) {
TChA SentenceBuf;
int c;
while (!SIn->Eof()) {
c = SIn->GetCh();
switch (c) {
case '\r':
case '\n': {
if (!SplitNewLineP) {
SentenceBuf += ' ';
break;
}
}
case '"' :
case '.' :
case '!' :
case ':' :
case ';' :
case '?' :
case '\t': {
if (SentenceBuf.Len() > 2) {
Sentences.Add(SentenceBuf);
printf("%s\n", SentenceBuf.CStr());
SentenceBuf.Clr();
}
break;
}
default:
SentenceBuf += c;
break;
}
}
if (SentenceBuf.Len() > 0) {
Sentences.Add(SentenceBuf);
}
}