Doxygen
Loading...
Searching...
No Matches
dstring.cpp File Reference
#include "dstring.h"
#include <cctype>
#include <climits>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include "regex.h"
Include dependency graph for dstring.cpp:

Go to the source code of this file.

Functions

char toLowerChar (char c)
static bool ok_in_base (char c, int base)
char * dstrdup (const char *str)
void dstrfree (const char *str)
 Frees the memory allocated using dstrdup().
char * dstrncpy (char *dst, const char *src, size_t len)
int dstricmp (const char *s1, const char *s2)
int dstrnicmp (const char *s1, const char *s2, size_t len)
DString substitute (const DString &s, const DString &src, const DString &dst)
 substitute all occurrences of src in s by dst
DString substitute (const DString &s, const DString &src, const DString &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

◆ dstrdup()

char * dstrdup ( const char * s)

Returns a copy of a string s. Note that memory is passed to the caller, use dstrfree() to release.

Definition at line 424 of file dstring.cpp.

425{
426 if ( !str ) return nullptr;
427 char *dst = new char[dstrlen(str)+1];
428 return strcpy( dst, str );
429}
uint32_t dstrlen(const char *str)
Returns the length of string str, or 0 if a null pointer is passed.
Definition dstring.h:39

References dstrlen().

◆ dstrfree()

void dstrfree ( const char * str)

Frees the memory allocated using dstrdup().

Definition at line 431 of file dstring.cpp.

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

◆ dstricmp()

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

Definition at line 444 of file dstring.cpp.

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

References toLowerChar().

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

◆ dstrncpy()

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

Definition at line 436 of file dstring.cpp.

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

◆ dstrnicmp()

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

Definition at line 462 of file dstring.cpp.

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

References toLowerChar().

Referenced by DString::contains(), dstrnicmp(), dstrnicmp(), dstrnicmp(), and DString::rfind_insensitive().

◆ ok_in_base()

bool ok_in_base ( char c,
int base )
static

Definition at line 161 of file dstring.cpp.

162{
163 if ( base <= 10 )
164 return c>='0' && c<='9' && (c-'0') < base;
165 else
166 return (c>='0' && c<='9') ||
167 (c >= 'a' && c < char('a'+base-10)) ||
168 (c >= 'A' && c < char('A'+base-10));
169}

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

◆ substitute() [1/2]

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

substitute all occurrences of src in s by dst

Definition at line 485 of file dstring.cpp.

486{
487 if (s.empty() || src.empty()) return s;
488 const char *q = nullptr, *p = nullptr;
489 size_t srcLen = src.length();
490 size_t dstLen = dst.length();
491 size_t resLen = 0;
492 if (srcLen!=dstLen)
493 {
494 int count = 0;
495 for (p = s.data(); (q=strstr(p,src.data()))!=nullptr; p=q+srcLen) count++;
496 resLen = s.length()+count*(dstLen-srcLen);
497 }
498 else // result has same size as s
499 {
500 resLen = s.length();
501 }
502 DString result(resLen, DString::ExplicitSize);
503 char *r = result.rawData();
504 for (p = s.data(); (q=strstr(p,src.data()))!=nullptr; p=q+srcLen)
505 {
506 int l = static_cast<int>(q-p);
507 memcpy(r,p,l);
508 r+=l;
509
510 if (dstLen>0) memcpy(r,dst.data(),dstLen);
511 r+=dstLen;
512 }
513 if (r)
514 {
515 dstrcpy(r,p);
516 }
517 //printf("substitute(%s,%s,%s)->%s\n",s,src,dst,result.data());
518 return result;
519}
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
@ ExplicitSize
Definition dstring.h:131
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition dstring.h:157
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:151
char * dstrcpy(char *dst, const char *src)
Definition dstring.h:42

References DString::data(), dstrcpy(), DString::empty(), DString::ExplicitSize, DString::length(), and DString::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(), HtmlGenerator::fixSpaces(), format_warn(), generateClassOrGlobalLink(), generateClassOrGlobalLink(), generateJSLink(), generateJSNavTree(), RefList::generatePage(), VhdlDocGen::getClassName(), DocPara::handleStartCode(), HtmlGenerator::init(), linkifyText(), linkToText(), makeDisplayName(), makeDisplayName(), matchExcludedSymbols(), Markdown::process(), Markdown::Private::processLink(), 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]

DString substitute ( const DString & s,
const DString & src,
const DString & 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 526 of file dstring.cpp.

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

References DString::data(), dstrcpy(), dstrncmp(), DString::empty(), DString::ExplicitSize, DString::length(), DString::rawData(), and DString::resize().

◆ toLowerChar()

char toLowerChar ( char c)
inline

Definition at line 29 of file dstring.cpp.

30{
31 return c>='A' && c<='Z' ? c|0x20 : c;
32}

Referenced by DString::contains(), dstricmp(), dstrnicmp(), and DString::rfind_insensitive().