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

488{
489 if ( dst > src )
490 {
491 char *d = static_cast<char *>(dst) + len - 1;
492 const char *s = static_cast<const char *>(src) + len - 1;
493 while ( len-- )
494 {
495 *d-- = *s--;
496 }
497 }
498 else if ( dst < src )
499 {
500 char *d = static_cast<char *>(dst);
501 const char *s = static_cast<const char *>(src);
502 while ( len-- )
503 {
504 *d++ = *s++;
505 }
506 }
507 return dst;
508}

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

511{
512 if ( !str ) return nullptr;
513 char *dst = new char[qstrlen(str)+1];
514 return strcpy( dst, str );
515}
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 517 of file qcstring.cpp.

518{
519 delete [](str);
520}

◆ qstricmp()

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

Definition at line 530 of file qcstring.cpp.

531{
532 if ( !s1 || !s2 )
533 {
534 return s1 == s2 ? 0 : static_cast<int>(s2 - s1);
535 }
536 int res = 0;
537 char c = 0;
538 for ( ; !(res = ((c=toLowerChar(*s1)) - toLowerChar(*s2))); s1++, s2++ )
539 {
540 if ( !c ) // strings are equal
541 {
542 break;
543 }
544 }
545 return res;
546}
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 522 of file qcstring.cpp.

523{
524 if ( !src ) return nullptr;
525 strncpy( dst, src, len );
526 if ( len > 0 ) dst[len-1] = '\0';
527 return dst;
528}

◆ qstrnicmp()

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

Definition at line 548 of file qcstring.cpp.

549{
550 if ( !s1 || !s2 )
551 {
552 return static_cast<int>(s2 - s1);
553 }
554 for ( ; len--; s1++, s2++ )
555 {
556 char c = toLowerChar(*s1);
557 int res = c-toLowerChar(*s2);
558 if ( res!=0 ) // strings are not equal
559 {
560 return res;
561 }
562 if ( c==0 ) // strings are equal
563 {
564 break;
565 }
566 }
567 return 0;
568}

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

572{
573 if (s.isEmpty() || src.isEmpty()) return s;
574 const char *q = nullptr, *p = nullptr;
575 size_t srcLen = src.length();
576 size_t dstLen = dst.length();
577 size_t resLen = 0;
578 if (srcLen!=dstLen)
579 {
580 int count = 0;
581 for (p = s.data(); (q=strstr(p,src.data()))!=nullptr; p=q+srcLen) count++;
582 resLen = s.length()+count*(dstLen-srcLen);
583 }
584 else // result has same size as s
585 {
586 resLen = s.length();
587 }
588 QCString result(resLen, QCString::ExplicitSize);
589 char *r = result.rawData();
590 for (p = s.data(); (q=strstr(p,src.data()))!=nullptr; p=q+srcLen)
591 {
592 int l = static_cast<int>(q-p);
593 memcpy(r,p,l);
594 r+=l;
595
596 if (dstLen>0) memcpy(r,dst.data(),dstLen);
597 r+=dstLen;
598 }
599 if (r)
600 {
601 qstrcpy(r,p);
602 }
603 //printf("substitute(%s,%s,%s)->%s\n",s,src,dst,result.data());
604 return result;
605}
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(), 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 612 of file qcstring.cpp.

613{
614 if (s.isEmpty() || src.isEmpty()) return s;
615 const char *p = nullptr, *q = nullptr;
616 size_t srcLen = src.length();
617 size_t dstLen = dst.length();
618 size_t resLen = 0;
619 if (srcLen!=dstLen)
620 {
621 int count = 0;
622 for (p=s.data(); (q=strstr(p,src.data()))!=nullptr; p=q+srcLen) count++;
623 resLen = s.length()+count*(dstLen-srcLen);
624 }
625 else // result has same size as s
626 {
627 resLen = s.length();
628 }
629 QCString result(resLen, QCString::ExplicitSize);
630 char *r = result.rawData();
631 for (p = s.data(); (q=strstr(p,src.data()))!=nullptr; p=q+srcLen)
632 {
633 // search a consecutive sequence of src
634 int seq = 0, skip = 0;
635 if (skip_seq)
636 {
637 for (const char *n=q+srcLen; qstrncmp(n,src.data(),srcLen)==0; seq=1+skip, n+=srcLen)
638 ++skip; // number of consecutive src after the current one
639
640 // verify the allowed number of consecutive src to skip
641 if (skip_seq > 0 && skip_seq != seq)
642 seq = skip = 0;
643 }
644
645 // skip a consecutive sequence of src when necessary
646 int l = static_cast<int>((q + seq * srcLen)-p);
647 memcpy(r,p,l);
648 r+=l;
649
650 if (skip)
651 {
652 // skip only the consecutive src found after the current one
653 q += skip * srcLen;
654 // the next loop will skip the current src, aka (p=q+srcLen)
655 continue;
656 }
657
658 if (dstLen>0) memcpy(r,dst.data(),dstLen);
659 r+=dstLen;
660 }
661 qstrcpy(r,p);
662 result.resize(strlen(result.data()));
663 //printf("substitute(%s,%s,%s)->%s\n",s,src,dst,result.data());
664 return result;
665}
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().