Doxygen
Loading...
Searching...
No Matches
dstring.cpp File Reference
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <ctype.h>
#include "dstring.h"
#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 420 of file dstring.cpp.

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

References dstrlen().

◆ dstrfree()

void dstrfree ( const char * str)

Frees the memory allocated using dstrdup().

Definition at line 427 of file dstring.cpp.

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

◆ dstricmp()

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

Definition at line 440 of file dstring.cpp.

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

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 432 of file dstring.cpp.

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

◆ dstrnicmp()

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

Definition at line 458 of file dstring.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 {
470 return res;
471 }
472 if ( c==0 ) // strings are equal
473 {
474 break;
475 }
476 }
477 return 0;
478}

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 157 of file dstring.cpp.

158{
159 if ( base <= 10 )
160 return c>='0' && c<='9' && (c-'0') < base;
161 else
162 return (c>='0' && c<='9') ||
163 (c >= 'a' && c < char('a'+base-10)) ||
164 (c >= 'A' && c < char('A'+base-10));
165}

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 481 of file dstring.cpp.

482{
483 if (s.empty() || src.empty()) return s;
484 const char *q = nullptr, *p = nullptr;
485 size_t srcLen = src.length();
486 size_t dstLen = dst.length();
487 size_t resLen = 0;
488 if (srcLen!=dstLen)
489 {
490 int count = 0;
491 for (p = s.data(); (q=strstr(p,src.data()))!=nullptr; p=q+srcLen) count++;
492 resLen = s.length()+count*(dstLen-srcLen);
493 }
494 else // result has same size as s
495 {
496 resLen = s.length();
497 }
498 DString result(resLen, DString::ExplicitSize);
499 char *r = result.rawData();
500 for (p = s.data(); (q=strstr(p,src.data()))!=nullptr; p=q+srcLen)
501 {
502 int l = static_cast<int>(q-p);
503 memcpy(r,p,l);
504 r+=l;
505
506 if (dstLen>0) memcpy(r,dst.data(),dstLen);
507 r+=dstLen;
508 }
509 if (r)
510 {
511 dstrcpy(r,p);
512 }
513 //printf("substitute(%s,%s,%s)->%s\n",s,src,dst,result.data());
514 return result;
515}
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:88
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:152
@ ExplicitSize
Definition dstring.h:135
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:161
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:155
char * dstrcpy(char *dst, const char *src)
Definition dstring.h:46

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 522 of file dstring.cpp.

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

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 25 of file dstring.cpp.

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

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