Doxygen
Loading...
Searching...
No Matches
qcstring.cpp File Reference
#include "qcstring.h"
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <ctype.h>
+ Include dependency graph for qcstring.cpp:

Go to the source code of this file.

Functions

char toLowerChar (char c)
 
static bool ok_in_base (char c, int base)
 
void * qmemmove (void *dst, const void *src, size_t len)
 
char * qstrdup (const char *str)
 Returns a copy of a string s.
 
void qstrfree (const char *str)
 Frees the memory allocated using qstrdup().
 
char * qstrncpy (char *dst, const char *src, size_t len)
 
int qstricmp (const char *s1, const char *s2)
 
int qstrnicmp (const char *s1, const char *s2, size_t len)
 
QCString substitute (const QCString &s, const QCString &src, const QCString &dst)
 substitute all occurrences of src in s by dst
 
QCString substitute (const QCString &s, const QCString &src, const QCString &dst, int skip_seq)
 substitute all occurrences of src in s by dst, but skip each consecutive sequence of src where the number consecutive src matches skip_seq; if skip_seq is negative, skip any number of consecutive src
 

Function Documentation

◆ ok_in_base()

static bool ok_in_base ( char c,
int base )
static

Definition at line 219 of file qcstring.cpp.

220{
221 if ( base <= 10 )
222 return c>='0' && c<='9' && (c-'0') < base;
223 else
224 return (c>='0' && c<='9') ||
225 (c >= 'a' && c < char('a'+base-10)) ||
226 (c >= 'A' && c < char('A'+base-10));
227}

Referenced by QCString::toLong(), QCString::toUInt64(), and QCString::toULong().

◆ qmemmove()

void * qmemmove ( void * dst,
const void * src,
size_t len )

Definition at line 402 of file qcstring.cpp.

403{
404 if ( dst > src ) {
405 char *d = static_cast<char *>(dst) + len - 1;
406 const char *s = static_cast<const char *>(src) + len - 1;
407 while ( len-- )
408 *d-- = *s--;
409 }
410 else if ( dst < src ) {
411 char *d = static_cast<char *>(dst);
412 const char *s = static_cast<const char *>(src);
413 while ( len-- )
414 *d++ = *s++;
415 }
416 return dst;
417}

◆ qstrdup()

char * qstrdup ( const char * s)

Returns a copy of a string s.

Note that memory is passed to the caller, use qstrfree() to release.

Definition at line 419 of file qcstring.cpp.

420{
421 if ( !str )
422 return nullptr;
423 char *dst = new char[qstrlen(str)+1];
424 return strcpy( dst, str );
425}
uint32_t qstrlen(const char *str)
Returns the length of string str, or 0 if a null pointer is passed.
Definition qcstring.h:58

References qstrlen().

◆ qstrfree()

void qstrfree ( const char * str)

Frees the memory allocated using qstrdup().

Definition at line 427 of file qcstring.cpp.

428{
429 delete[](str);
430}

◆ qstricmp()

int qstricmp ( const char * s1,
const char * s2 )

Definition at line 442 of file qcstring.cpp.

443{
444 if ( !s1 || !s2 )
445 {
446 return s1 == s2 ? 0 : static_cast<int>(s2 - s1);
447 }
448 int res = 0;
449 char c = 0;
450 for ( ; !(res = ((c=toLowerChar(*s1)) - toLowerChar(*s2))); s1++, s2++ )
451 {
452 if ( !c ) // strings are equal
453 break;
454 }
455 return res;
456}
char toLowerChar(char c)
Definition qcstring.cpp:24

References toLowerChar().

Referenced by compareString(), VhdlDocGen::findAllArchitectures(), DocGroup::findExistingGroup(), FlowChart::findLabel(), VhdlDocGen::findVhdlClass(), mainPageHasOwnTitle(), qstricmp(), qstricmp(), qstricmp(), qstricmp_sort(), readConfiguration(), stripFromPath(), transcodeCharacterBuffer(), transcodeCharacterStringToUTF8(), FlowChart::writeFlowLinks(), ClassDefImpl::writeIncludeFilesForSlice(), writeIndex(), and VhdlDocGen::writeProcedureProto().

◆ qstrncpy()

char * qstrncpy ( char * dst,
const char * src,
size_t len )

Definition at line 432 of file qcstring.cpp.

433{
434 if ( !src )
435 return nullptr;
436 strncpy( dst, src, len );
437 if ( len > 0 )
438 dst[len-1] = '\0';
439 return dst;
440}

Referenced by do_warn().

◆ qstrnicmp()

int qstrnicmp ( const char * s1,
const char * s2,
size_t len )

Definition at line 458 of file qcstring.cpp.

459{
460 if ( !s1 || !s2 )
461 {
462 return static_cast<int>(s2 - s1);
463 }
464 for ( ; len--; s1++, s2++ )
465 {
466 char c = toLowerChar(*s1);
467 int res = c-toLowerChar(*s2);
468 if ( res!=0 ) // strings are not equal
469 return res;
470 if ( c==0 ) // strings are equal
471 break;
472 }
473 return 0;
474}

References toLowerChar().

Referenced by QCString::contains(), QCString::find(), QCString::findRev(), qstrnicmp(), qstrnicmp(), and qstrnicmp().

◆ substitute() [1/2]

QCString substitute ( const QCString & s,
const QCString & src,
const QCString & dst )

substitute all occurrences of src in s by dst

Definition at line 477 of file qcstring.cpp.

478{
479 if (s.isEmpty() || src.isEmpty()) return s;
480 const char *q = nullptr, *p = nullptr;
481 size_t srcLen = src.length();
482 size_t dstLen = dst.length();
483 size_t resLen = 0;
484 if (srcLen!=dstLen)
485 {
486 int count = 0;
487 for (p = s.data(); (q=strstr(p,src.data()))!=nullptr; p=q+srcLen) count++;
488 resLen = s.length()+count*(dstLen-srcLen);
489 }
490 else // result has same size as s
491 {
492 resLen = s.length();
493 }
494 QCString result(resLen, QCString::ExplicitSize);
495 char *r = result.rawData();
496 for (p = s.data(); (q=strstr(p,src.data()))!=nullptr; p=q+srcLen)
497 {
498 int l = static_cast<int>(q-p);
499 memcpy(r,p,l);
500 r+=l;
501
502 if (dstLen>0) memcpy(r,dst.data(),dstLen);
503 r+=dstLen;
504 }
505 if (r)
506 {
507 qstrcpy(r,p);
508 }
509 //printf("substitute(%s,%s,%s)->%s\n",s,src,dst,result.data());
510 return result;
511}
This is an alternative implementation of QCString.
Definition qcstring.h:101
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:153
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
@ ExplicitSize
Definition qcstring.h:133
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition qcstring.h:159
char * qstrcpy(char *dst, const char *src)
Definition qcstring.h:61

References QCString::data(), QCString::ExplicitSize, QCString::isEmpty(), QCString::length(), qstrcpy(), and QCString::rawData().

Referenced by abbreviate(), addEnumValuesToEnums(), FlowChart::addFlowChart(), addFrom(), MemberDefImpl::addListReference(), addMemberFunction(), addModule(), addPageToContext(), Markdown::Private::addStrEscapeUtf8Nbsp(), addVariable(), addVariableToClass(), buildListOfUsingDecls(), buildNamespaceList(), DocParser::checkUnOrMultipleDocumentedParams(), convertFileId2Var(), ResourceMgr::copyResourceAs(), Portable::correctPath(), MemberDefImpl::displayDefinition(), findDirDocumentation(), DocParser::findDocsForMemberOrCompound(), findGlobalMember(), findGroupScope(), findMember(), findUsingDeclarations(), findUsingDirectives(), fixSpaces(), format_warn(), generateClassOrGlobalLink(), generateClassOrGlobalLink(), generateJSNavTree(), RefList::generatePage(), VhdlDocGen::getClassName(), getDefsOld(), DocPara::handleStartCode(), HtmlGenerator::init(), linkToText(), makeDisplayName(), makeDisplayName(), matchExcludedSymbols(), Markdown::process(), Markdown::Private::processLink(), processTagLessClasses(), resolveRef(), DotFilePatcher::run(), SearchIndex::setCurrentDoc(), stripIndentation(), substitute(), substituteHtmlKeywords(), substituteLatexKeywords(), Portable::system(), ConfigImpl::takeStartComment(), ConfigImpl::takeStoreRepl(), ConfigImpl::takeUserComment(), unescapeCRef(), validatingParseDoc(), warn_line(), MemberDefImpl::warnIfUndocumented(), writeAlphabeticalClassList(), MemberDefImpl::writeDeclaration(), MemberList::writeDeclarations(), writeDefArgumentList(), writeDefaultLayoutFile(), MemberDefImpl::writeDocumentation(), writeJavaScriptSearchIndex(), HtmlGenerator::writeNavigationPath(), PlantumlManager::writePlantUMLSource(), HtmlGenerator::writeSearchData(), HtmlGenerator::writeSearchPage(), and VhdlDocGen::writeVHDLTypeDocumentation().

◆ substitute() [2/2]

QCString substitute ( const QCString & s,
const QCString & src,
const QCString & dst,
int skip_seq )

substitute all occurrences of src in s by dst, but skip each consecutive sequence of src where the number consecutive src matches skip_seq; if skip_seq is negative, skip any number of consecutive src

Definition at line 518 of file qcstring.cpp.

519{
520 if (s.isEmpty() || src.isEmpty()) return s;
521 const char *p = nullptr, *q = nullptr;
522 size_t srcLen = src.length();
523 size_t dstLen = dst.length();
524 size_t resLen = 0;
525 if (srcLen!=dstLen)
526 {
527 int count = 0;
528 for (p=s.data(); (q=strstr(p,src.data()))!=nullptr; p=q+srcLen) count++;
529 resLen = s.length()+count*(dstLen-srcLen);
530 }
531 else // result has same size as s
532 {
533 resLen = s.length();
534 }
535 QCString result(resLen, QCString::ExplicitSize);
536 char *r = result.rawData();
537 for (p = s.data(); (q=strstr(p,src.data()))!=nullptr; p=q+srcLen)
538 {
539 // search a consecutive sequence of src
540 int seq = 0, skip = 0;
541 if (skip_seq)
542 {
543 for (const char *n=q+srcLen; qstrncmp(n,src.data(),srcLen)==0; seq=1+skip, n+=srcLen)
544 ++skip; // number of consecutive src after the current one
545
546 // verify the allowed number of consecutive src to skip
547 if (skip_seq > 0 && skip_seq != seq)
548 seq = skip = 0;
549 }
550
551 // skip a consecutive sequence of src when necessary
552 int l = static_cast<int>((q + seq * srcLen)-p);
553 memcpy(r,p,l);
554 r+=l;
555
556 if (skip)
557 {
558 // skip only the consecutive src found after the current one
559 q += skip * srcLen;
560 // the next loop will skip the current src, aka (p=q+srcLen)
561 continue;
562 }
563
564 if (dstLen>0) memcpy(r,dst.data(),dstLen);
565 r+=dstLen;
566 }
567 qstrcpy(r,p);
568 result.resize(strlen(result.data()));
569 //printf("substitute(%s,%s,%s)->%s\n",s,src,dst,result.data());
570 return result;
571}
int qstrncmp(const char *str1, const char *str2, size_t len)
Definition qcstring.h:75

References QCString::data(), QCString::ExplicitSize, QCString::isEmpty(), QCString::length(), qstrcpy(), qstrncmp(), QCString::rawData(), and QCString::resize().

◆ toLowerChar()

char toLowerChar ( char c)
inline

Definition at line 24 of file qcstring.cpp.

25{
26 return c>='A' && c<='Z' ? c|0x20 : c;
27}

Referenced by QCString::contains(), QCString::find(), QCString::findRev(), qstricmp(), and qstrnicmp().