@@ -104,28 +104,32 @@ TextGeneratorOLImpl::TextGeneratorOLImpl(OutputList &ol) : m_ol(ol)
104104{
105105}
106106
107- void TextGeneratorOLImpl::writeString (const QCString & s,bool keepSpaces) const
107+ void TextGeneratorOLImpl::writeString (std::string_view s,bool keepSpaces) const
108108{
109- if (s.isEmpty ()) return ;
109+ if (s.empty ()) return ;
110110 // printf("TextGeneratorOlImpl::writeString('%s',%d)\n",s,keepSpaces);
111111 if (keepSpaces)
112112 {
113- const char *p=s.data ();
114- if (p)
113+ char cs[2 ];
114+ char c;
115+ cs[1 ]=' \0 ' ;
116+ for (size_t i=0 ;i<s.length ();i++)
115117 {
116- char cs[2 ];
117- char c;
118- cs[1 ]=' \0 ' ;
119- while ((c=*p++))
118+ c = s[i];
119+ if (c==' ' )
120+ {
121+ m_ol.writeNonBreakableSpace (1 );
122+ }
123+ else
120124 {
121- if (c== ' ' ) m_ol. writeNonBreakableSpace ( 1 ) ;
122- else cs[ 0 ]=c, m_ol.docify (cs);
125+ cs[ 0 ]=c ;
126+ m_ol.docify (cs);
123127 }
124128 }
125129 }
126130 else
127131 {
128- m_ol.docify (s );
132+ m_ol.docify (QCString (s) );
129133 }
130134}
131135
@@ -140,11 +144,11 @@ void TextGeneratorOLImpl::writeBreak(int indent) const
140144}
141145
142146void TextGeneratorOLImpl::writeLink (const QCString &extRef,const QCString &file,
143- const QCString &anchor,const QCString & text
147+ const QCString &anchor,std::string_view text
144148 ) const
145149{
146150 // printf("TextGeneratorOlImpl::writeLink('%s')\n",text);
147- m_ol.writeObjectLink (extRef,file,anchor,text);
151+ m_ol.writeObjectLink (extRef,file,anchor,QCString ( text) );
148152}
149153
150154// ------------------------------------------------------------------------
@@ -892,15 +896,15 @@ void linkifyText(const TextGeneratorIntf &out, const Definition *scope,
892896{
893897 if (text.isEmpty ()) return ;
894898 // printf("linkify='%s'\n",qPrint(text));
895- std::string txtStr=text.str ();
899+ std::string_view txtStr=text.view ();
896900 size_t strLen = txtStr.length ();
897901 if (strLen==0 ) return ;
898902
899903 static const reg::Ex regExp (R"( (::)?\a[\w~!\\.:$"]*)" );
900904 reg::Iterator it (txtStr,regExp);
901905 reg::Iterator end;
902906
903- // printf("linkifyText scope=%s fileScope=%s strtxt=%s strlen=%d external=%d\n",
907+ // printf("linkifyText scope=%s fileScope=%s strtxt=%s strlen=%zu external=%d\n",
904908 // scope ? qPrint(scope->name()):"<none>",
905909 // fileScope ? qPrint(fileScope->name()) : "<none>",
906910 // qPrint(txtStr),strLen,external);
@@ -915,8 +919,8 @@ void linkifyText(const TextGeneratorIntf &out, const Definition *scope,
915919 floatingIndex+=newIndex-skipIndex+matchLen;
916920 if (newIndex>0 && txtStr.at (newIndex-1 )==' 0' ) // ignore hex numbers (match x00 in 0x00)
917921 {
918- std::string part = txtStr.substr (skipIndex,newIndex+matchLen-skipIndex);
919- out.writeString (part. c_str () ,keepSpaces);
922+ std::string_view part = txtStr.substr (skipIndex,newIndex+matchLen-skipIndex);
923+ out.writeString (part,keepSpaces);
920924 skipIndex=index=newIndex+matchLen;
921925 continue ;
922926 }
@@ -932,7 +936,7 @@ void linkifyText(const TextGeneratorIntf &out, const Definition *scope,
932936 // printf("floatingIndex=%d strlen=%d autoBreak=%d\n",floatingIndex,strLen,autoBreak);
933937 if (strLen>35 && floatingIndex>30 && autoBreak) // try to insert a split point
934938 {
935- std::string splitText = txtStr.substr (skipIndex,newIndex-skipIndex);
939+ std::string_view splitText = txtStr.substr (skipIndex,newIndex-skipIndex);
936940 size_t splitLength = splitText.length ();
937941 size_t offset=1 ;
938942 size_t i = splitText.find (' ,' );
@@ -942,26 +946,26 @@ void linkifyText(const TextGeneratorIntf &out, const Definition *scope,
942946 // printf("splitText=[%s] len=%d i=%d offset=%d\n",qPrint(splitText),splitLength,i,offset);
943947 if (i!=std::string::npos) // add a link-break at i in case of Html output
944948 {
945- std::string part1 = splitText.substr (0 ,i+offset);
946- out.writeString (part1. c_str () ,keepSpaces);
949+ std::string_view part1 = splitText.substr (0 ,i+offset);
950+ out.writeString (part1,keepSpaces);
947951 out.writeBreak (indentLevel==0 ? 0 : indentLevel+1 );
948- std::string part2 = splitText.substr (i+offset);
949- out.writeString (part2. c_str () ,keepSpaces);
952+ std::string_view part2 = splitText.substr (i+offset);
953+ out.writeString (part2,keepSpaces);
950954 floatingIndex=splitLength-i-offset+matchLen;
951955 }
952956 else
953957 {
954- out.writeString (splitText. c_str () ,keepSpaces);
958+ out.writeString (splitText,keepSpaces);
955959 }
956960 }
957961 else
958962 {
959963 // ol.docify(txtStr.mid(skipIndex,newIndex-skipIndex));
960- std::string part = txtStr.substr (skipIndex,newIndex-skipIndex);
961- out.writeString (part. c_str () ,keepSpaces);
964+ std::string_view part = txtStr.substr (skipIndex,newIndex-skipIndex);
965+ out.writeString (part,keepSpaces);
962966 }
963967 // get word from string
964- std::string word=txtStr.substr (newIndex,matchLen);
968+ std::string_view word=txtStr.substr (newIndex,matchLen);
965969 QCString matchWord = substitute (substitute (QCString (word)," \\ " ," ::" )," ." ," ::" );
966970 // printf("linkifyText word=%s matchWord=%s scope=%s\n",
967971 // qPrint(word),qPrint(matchWord),scope ? qPrint(scope->name()) : "<none>");
@@ -977,15 +981,15 @@ void linkifyText(const TextGeneratorIntf &out, const Definition *scope,
977981 const MemberDef *typeDef = resolver.getTypedef ();
978982 if (typeDef) // First look at typedef then class, see bug 584184.
979983 {
980- // printf("Found typedef %s\n",qPrint(typeDef->name()));
981984 if (external ? typeDef->isLinkable () : typeDef->isLinkableInProject ())
982985 {
983986 if (typeDef->getOuterScope ()!=self)
984987 {
988+ // printf("Found typedef %s word='%s'\n",qPrint(typeDef->name()),qPrint(word));
985989 out.writeLink (typeDef->getReference (),
986990 typeDef->getOutputFileBase (),
987991 typeDef->anchor (),
988- word. c_str () );
992+ word);
989993 found=TRUE ;
990994 }
991995 }
@@ -995,14 +999,14 @@ void linkifyText(const TextGeneratorIntf &out, const Definition *scope,
995999 {
9961000 if (self==nullptr || cd_->qualifiedName ()!=self->qualifiedName ())
9971001 {
998- out.writeLink (cd_->getReference (),cd_->getOutputFileBase (),cd_->anchor (),word.c_str ());
1002+ // printf("Found compound %s word='%s'\n",qPrint(cd->name()),qPrint(word));
1003+ out.writeLink (cd_->getReference (),cd_->getOutputFileBase (),cd_->anchor (),word);
9991004 found=TRUE ;
10001005 }
10011006 }
10021007 };
10031008 if (!found && (cd || (cd=getClass (matchWord))))
10041009 {
1005- // printf("Found class %s\n",qPrint(cd->name()));
10061010 writeCompoundName (cd);
10071011 }
10081012 else if ((cd=getClass (matchWord+" -p" ))) // search for Obj-C protocols as well
@@ -1035,7 +1039,7 @@ void linkifyText(const TextGeneratorIntf &out, const Definition *scope,
10351039 }
10361040
10371041 // printf("ScopeName=%s\n",qPrint(scopeName));
1038- // if (!found) printf("Trying to link %s in %s \n",qPrint(word),qPrint(scopeName));
1042+ // if (!found) printf("Trying to link '%s' in '%s' \n",qPrint(word),qPrint(scopeName));
10391043 if (!found)
10401044 {
10411045 GetDefInput input (scopeName,matchWord,QCString ());
@@ -1060,9 +1064,9 @@ void linkifyText(const TextGeneratorIntf &out, const Definition *scope,
10601064 )
10611065 )
10621066 {
1067+ // printf("found symbol %s word='%s'\n",qPrint(result.md->name()),qPrint(word));
10631068 out.writeLink (result.md ->getReference (),result.md ->getOutputFileBase (),
1064- result.md ->anchor (),word.c_str ());
1065- // printf("found symbol %s\n",qPrint(matchWord));
1069+ result.md ->anchor (),word);
10661070 found=TRUE ;
10671071 }
10681072 }
@@ -1072,16 +1076,16 @@ void linkifyText(const TextGeneratorIntf &out, const Definition *scope,
10721076
10731077 if (!found) // add word to the result
10741078 {
1075- out.writeString (word. c_str () ,keepSpaces);
1079+ out.writeString (word,keepSpaces);
10761080 }
10771081 // set next start point in the string
10781082 // printf("index=%d/%d\n",index,txtStr.length());
10791083 skipIndex=index=newIndex+matchLen;
10801084 }
10811085 // add last part of the string to the result.
10821086 // ol.docify(txtStr.right(txtStr.length()-skipIndex));
1083- std::string lastPart = txtStr.substr (skipIndex);
1084- out.writeString (lastPart. c_str () ,keepSpaces);
1087+ std::string_view lastPart = txtStr.substr (skipIndex);
1088+ out.writeString (lastPart,keepSpaces);
10851089}
10861090
10871091void writeMarkerList (OutputList &ol,const std::string &markerText,size_t numMarkers,
0 commit comments