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)
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()

bool ok_in_base ( char c,
int base )
static

Definition at line 224 of file qcstring.cpp.

225{
226 if ( base <= 10 )
227 return c>='0' && c<='9' && (c-'0') < base;
228 else
229 return (c>='0' && c<='9') ||
230 (c >= 'a' && c < char('a'+base-10)) ||
231 (c >= 'A' && c < char('A'+base-10));
232}

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

◆ qmemmove()

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

Definition at line 407 of file qcstring.cpp.

408{
409 if ( dst > src ) {
410 char *d = static_cast<char *>(dst) + len - 1;
411 const char *s = static_cast<const char *>(src) + len - 1;
412 while ( len-- )
413 *d-- = *s--;
414 }
415 else if ( dst < src ) {
416 char *d = static_cast<char *>(dst);
417 const char *s = static_cast<const char *>(src);
418 while ( len-- )
419 *d++ = *s++;
420 }
421 return dst;
422}

◆ 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 424 of file qcstring.cpp.

425{
426 if ( !str )
427 return nullptr;
428 char *dst = new char[qstrlen(str)+1];
429 return strcpy( dst, str );
430}
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 432 of file qcstring.cpp.

433{
434 delete[](str);
435}

◆ qstricmp()

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

Definition at line 447 of file qcstring.cpp.

448{
449 if ( !s1 || !s2 )
450 {
451 return s1 == s2 ? 0 : static_cast<int>(s2 - s1);
452 }
453 int res = 0;
454 char c = 0;
455 for ( ; !(res = ((c=toLowerChar(*s1)) - toLowerChar(*s2))); s1++, s2++ )
456 {
457 if ( !c ) // strings are equal
458 break;
459 }
460 return res;
461}
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 437 of file qcstring.cpp.

438{
439 if ( !src )
440 return nullptr;
441 strncpy( dst, src, len );
442 if ( len > 0 )
443 dst[len-1] = '\0';
444 return dst;
445}

◆ qstrnicmp()

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

Definition at line 463 of file qcstring.cpp.

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

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 482 of file qcstring.cpp.

483{
484 if (s.isEmpty() || src.isEmpty()) return s;
485 const char *q = nullptr, *p = nullptr;
486 size_t srcLen = src.length();
487 size_t dstLen = dst.length();
488 size_t resLen = 0;
489 if (srcLen!=dstLen)
490 {
491 int count = 0;
492 for (p = s.data(); (q=strstr(p,src.data()))!=nullptr; p=q+srcLen) count++;
493 resLen = s.length()+count*(dstLen-srcLen);
494 }
495 else // result has same size as s
496 {
497 resLen = s.length();
498 }
499 QCString result(resLen, QCString::ExplicitSize);
500 char *r = result.rawData();
501 for (p = s.data(); (q=strstr(p,src.data()))!=nullptr; p=q+srcLen)
502 {
503 int l = static_cast<int>(q-p);
504 memcpy(r,p,l);
505 r+=l;
506
507 if (dstLen>0) memcpy(r,dst.data(),dstLen);
508 r+=dstLen;
509 }
510 if (r)
511 {
512 qstrcpy(r,p);
513 }
514 //printf("substitute(%s,%s,%s)->%s\n",s,src,dst,result.data());
515 return result;
516}
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:166
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:163
@ ExplicitSize
Definition qcstring.h:146
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:172
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(), addGlobalFunction(), HtmlHelpIndex::addItem(), MemberDefImpl::addListReference(), addMemberFunction(), addMethodToClass(), addModule(), addPageToContext(), Markdown::Private::addStrEscapeUtf8Nbsp(), addVariable(), addVariableToClass(), buildListOfUsingDecls(), buildNamespaceList(), convertFileId2Var(), Portable::correctPath(), MemberDefImpl::displayDefinition(), findDirDocumentation(), DocParser::findDocsForMemberOrCompound(), findGroupScope(), findMember(), findUsingDeclarations(), findUsingDirectives(), fixSpaces(), format_warn(), generateClassOrGlobalLink(), generateClassOrGlobalLink(), generateJSNavTree(), RefList::generatePage(), VhdlDocGen::getClassName(), getDefsOld(), DocPara::handleStartCode(), HtmlGenerator::init(), linkifyText(), 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 523 of file qcstring.cpp.

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