summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorShawn Hussey <shawn@zeroc.com>2011-09-02 17:05:21 -0230
committerShawn Hussey <shawn@zeroc.com>2011-09-02 17:05:21 -0230
commit2662066056fb74374f926608e90ce48f2995a748 (patch)
treeb64bcc0e831cd48e0eceb6a7288d6d9b4ef55467 /cpp
parentFixing markup escaping for slice2confluence. (diff)
downloadice-2662066056fb74374f926608e90ce48f2995a748.tar.bz2
ice-2662066056fb74374f926608e90ce48f2995a748.tar.xz
ice-2662066056fb74374f926608e90ce48f2995a748.zip
Deprecation handling for slice2confluence.
Diffstat (limited to 'cpp')
-rw-r--r--cpp/src/slice2confluence/ConfluenceOutput.cpp157
-rwxr-xr-xcpp/src/slice2confluence/Gen.cpp63
2 files changed, 170 insertions, 50 deletions
diff --git a/cpp/src/slice2confluence/ConfluenceOutput.cpp b/cpp/src/slice2confluence/ConfluenceOutput.cpp
index 2120541d025..2f44679a474 100644
--- a/cpp/src/slice2confluence/ConfluenceOutput.cpp
+++ b/cpp/src/slice2confluence/ConfluenceOutput.cpp
@@ -75,7 +75,7 @@ string
Confluence::ConfluenceOutput::escapeComment(string comment)
{
list< pair<unsigned int,unsigned int> > escaperLimits = getMarkerLimits(comment);
- string escapeChars = "\\{}-*|[]";
+ string escapeChars = "\\{}-_*|[]";
//for each escape character
for (string::iterator i = escapeChars.begin(); i < escapeChars.end(); ++i)
@@ -107,6 +107,10 @@ Confluence::ConfluenceOutput::escapeComment(string comment)
{
replacement = "&#124;";
}
+ else if (c == "_")
+ {
+ replacement = "&#95;";
+ }
else if (c == "[")
{
replacement = "&#91;";
@@ -140,26 +144,21 @@ Confluence::ConfluenceOutput::escapeComment(string comment)
}
else
{
-// cout << "skipping ahead to: '" << comment.substr(region->second) << "'"<< endl;
+ //skip ahead past the marked section
pos = comment.find(c, region->second+1);
}
}
}
-
-// cout << "COMMENT: " << comment << endl;
comment = removeMarkers(comment);
- size_t f = comment.find("This exception is raised if the ");
- if (f != string::npos)
- {
- cout << "AFTER: " << comment << endl;
- }
return comment;
}
string
Confluence::ConfluenceOutput::convertCommentHTML(string comment)
{
- escapeComment(comment);
+ comment = escapeComment(comment);
+
+ bool italics = false;
size_t tagStart = comment.find("<");
while (tagStart != string::npos)
@@ -175,10 +174,54 @@ Confluence::ConfluenceOutput::convertCommentHTML(string comment)
}
size_t spacepos = tag.find(" ");
+ list<pair<string,string> > attributes;
+
+ string rest;
if (spacepos != string::npos)
{
- //strip attributes from tag
+ //get the rest and seperate into attrs
+ rest = tag.substr(spacepos);
+
+ //get just the tag
tag = tag.substr(0, spacepos);
+
+ size_t nextSpace = 0;
+ size_t lastSpace = 0;
+ do
+ {
+ lastSpace = nextSpace;
+ nextSpace = rest.find(" ", lastSpace+1); //rest starts with a space
+
+ string setting;
+ if (nextSpace == string::npos)
+ {
+ setting = rest.substr(lastSpace);
+ }
+ else {
+ setting = rest.substr(lastSpace, nextSpace-lastSpace);
+ }
+
+ size_t eqPos = setting.find("=");
+ if (eqPos != string::npos)
+ {
+ string aName = setting.substr(1, eqPos-1);
+ string aVal = setting.substr(eqPos+1);
+ //remove quotes from val
+ size_t qPos = aVal.find("\"");
+ while (qPos != string::npos)
+ {
+ aVal.erase(qPos, 1);
+ qPos = aVal.find("\"");
+ }
+
+ pair<string,string> p = make_pair(aName, aVal);
+ attributes.push_back(p);
+ }
+ else
+ {
+ //bad attribute, ignore
+ }
+ } while (nextSpace != string::npos);
}
if (!strcmp(tag.c_str(), "tt"))
@@ -194,13 +237,43 @@ Confluence::ConfluenceOutput::convertCommentHTML(string comment)
}
else if (!strcmp(tag.c_str(), "p"))
{
+ //special case: Some classes add markup
+ for (list<pair<string,string> >::iterator i = attributes.begin(); i != attributes.end(); ++i)
+ {
+ if (i->first == "class" && i->second == "Note")
+ {
+ italics = true;
+ break;
+ }
+ if (i->first == "class" && i->second == "Deprecated")
+ {
+ italics = true;
+ break;
+ }
+ }
+
if (!isEndTag)
{
- replacement = "\n\n";
+ if (italics)
+ {
+ replacement = "\n\n_";
+ }
+ else
+ {
+ replacement = "\n\n";
+ }
}
else
{
- replacement = "\n\n";
+ if (italics)
+ {
+ replacement = "_\n\n";
+ italics = false;
+ }
+ else
+ {
+ replacement = "\n\n";
+ }
}
}
else if (!strcmp(tag.c_str(), "ol"))
@@ -294,8 +367,53 @@ Confluence::ConfluenceOutput::convertCommentHTML(string comment)
}
//apply replacement
- comment.replace(tagStart, tagEnd + 1 - tagStart, replacement);
+ if (!strcmp(tag.c_str(), "p"))
+ {
+ comment.erase(tagStart, tagEnd + 1 - tagStart);
+ size_t displace = comment.find_first_not_of(" \n\r\t", tagStart); //skip ahead over whitespace
+ comment.insert(displace, replacement);
+ }
+ else
+ {
+ comment.replace(tagStart, tagEnd + 1 - tagStart, replacement); //don't skip whitespace
+ }
+
+
+ //special case: terminate <p> (and any italics) on double newline or end of comment
+ size_t dnl = comment.find("\n\n", tagStart+replacement.size());
tagStart = comment.find("<");
+
+ if (italics)
+ {
+ if (tagStart == string::npos && dnl == string::npos)
+ {
+ //end italics before javadoc markup
+ size_t atPos = comment.find("@", tagStart+replacement.size());
+ if (atPos != string::npos)
+ {
+ //found markup. now move to the last non-whitespace char before the markup and end italics
+ string before = comment.substr(0, atPos);
+ size_t endLocation = before.find_last_not_of(" \n\r\t");
+ comment.insert(endLocation, "_");
+ italics = false;
+ }
+ else
+ {
+ //no markup; end of comment
+ size_t endLocation = comment.find_last_not_of(" \n\r\t");
+ comment.insert(endLocation, "_");
+ italics = false;
+ }
+ }
+ else if (dnl != string::npos && (tagStart == string::npos || dnl < tagStart))
+ {
+ string before = comment.substr(0, dnl);
+ size_t endLocation = before.find_last_not_of(" \n\r\t");
+ comment.insert(endLocation, "_");
+ italics = false;
+ }
+ }
+
}
return comment;
}
@@ -668,13 +786,12 @@ Confluence::ConfluenceOutput::getMarkerLimits(const string& str)
if (end != string::npos)
{
pair<unsigned int, unsigned int> p = make_pair((unsigned int)start, (unsigned int)end+TEMP_ESCAPER_END.size());
-// cout << "adding pair (" << p.first << ", " << p.second << ") for '" << str << "'" << endl;
pairs.push_back(p);
start = str.find(TEMP_ESCAPER_START, end+TEMP_ESCAPER_END.size());
}
else
{
- cerr << "getEscaperLimits FOUND START OF ESCAPER WITH NO MATCHING END IN STRING:" << endl << str.substr(start) << endl;
+ cerr << "getEscaperLimits FOUND START OF ESCAPE MARKER WITH NO MATCHING END IN STRING:" << endl << str.substr(start) << endl;
break;
}
}
@@ -686,7 +803,6 @@ string
Confluence::ConfluenceOutput::removeMarkers(string str)
{
//remove starts
-// cout << "REMOVE STARTS FROM STR: " << str << endl;
size_t start = str.find(TEMP_ESCAPER_START);
while (start != string::npos)
{
@@ -694,8 +810,6 @@ Confluence::ConfluenceOutput::removeMarkers(string str)
start = str.find(TEMP_ESCAPER_START, start);
}
-// cout << "WITH STARTS REMOVED: " << str << endl;
-
//remove ends
size_t end = str.find(TEMP_ESCAPER_END);
while (end != string::npos)
@@ -703,11 +817,6 @@ Confluence::ConfluenceOutput::removeMarkers(string str)
str.erase(end, TEMP_ESCAPER_END.size());
end = str.find(TEMP_ESCAPER_END, end);
}
- size_t f = str.find("This exception is raised if the ");
- if (f != string::npos)
- {
- cout << "WITH STOPS REMOVED?: " << str << endl;
- }
return str;
}
diff --git a/cpp/src/slice2confluence/Gen.cpp b/cpp/src/slice2confluence/Gen.cpp
index bd141698902..2753c8f23c7 100755
--- a/cpp/src/slice2confluence/Gen.cpp
+++ b/cpp/src/slice2confluence/Gen.cpp
@@ -462,7 +462,9 @@ Slice::GeneratorBase::printComment(const ContainedPtr& p, const ContainerPtr& co
{
comment.erase(pos + 1);
_out.zeroIndent();
- _out << removeNewlines(comment);
+
+ _out << comment;
+
_out.restoreIndent();
_out << "\n";
}
@@ -733,7 +735,7 @@ Slice::GeneratorBase::getSummary(const ContainedPtr& p, const ContainerPtr& modu
if(deprecated)
{
- oss << "\nDeprecated.\n";
+ oss << " _(Deprecated)_ \n";
}
return oss.str();
}
@@ -1199,7 +1201,7 @@ Slice::GeneratorBase::getComment(const ContainedPtr& contained, const ContainerP
cerr << contained->file() << ": warning: summary size (" << summarySize << ") exceeds " << _warnSummary
<< " characters: `" << comment << "'" << endl;
}
- return removeNewlines(_out.convertCommentHTML(comment));
+ return trim(_out.convertCommentHTML(removeNewlines(comment)));
}
string
@@ -2093,7 +2095,7 @@ Slice::ModuleGenerator::generate(const ModulePtr& m)
deprecateReason = "This module is deprecated.";
if(metadata.find("deprecate:") == 0 && metadata.size() > 10)
{
- deprecateReason = metadata.substr(10);
+ deprecateReason = "_" + trim(metadata.substr(10)) + "_";
}
}
start("h2");
@@ -2437,6 +2439,10 @@ Slice::ModuleGenerator::visitContainer(const ContainerPtr& p)
{
_out << "local ";
}
+ else
+ {
+ _out << " ";
+ }
TypePtr type = (*q)->type();
_out << "sequence&lt;" << toString(type, p, false, true) << "&gt; " << toString(*q, p);
end();
@@ -2447,7 +2453,7 @@ Slice::ModuleGenerator::visitContainer(const ContainerPtr& p)
deprecateReason = "This type is deprecated.";
if(metadata.find("deprecate:") == 0 && metadata.size() > 10)
{
- deprecateReason = metadata.substr(10);
+ deprecateReason = "_" + trim(metadata.substr(10)) + "_";
}
}
@@ -2470,6 +2476,10 @@ Slice::ModuleGenerator::visitContainer(const ContainerPtr& p)
{
_out << "local ";
}
+ else
+ {
+ _out << " ";
+ }
TypePtr keyType = (*q)->keyType();
TypePtr valueType = (*q)->valueType();
_out << "dictionary&lt;" << toString(keyType, p, false, true) << ", "
@@ -2482,7 +2492,7 @@ Slice::ModuleGenerator::visitContainer(const ContainerPtr& p)
deprecateReason = "This type is deprecated.";
if(metadata.find("deprecate:") == 0 && metadata.size() > 10)
{
- deprecateReason = removeNewlines(metadata.substr(10));
+ deprecateReason = "_" + trim(metadata.substr(10)) + "_";
}
}
@@ -2498,7 +2508,7 @@ Slice::ModuleGenerator::visitContainer(const ContainerPtr& p)
end();
for(ConstList::const_iterator q = consts.begin(); q != consts.end(); ++q)
{
- start("tt");
+ start("h3");
_out << "const " << toString((*q)->type(), p, false, true) << " " << toString(*q, p) << " = ";
if(EnumPtr::dynamicCast((*q)->type()))
{
@@ -2513,17 +2523,15 @@ Slice::ModuleGenerator::visitContainer(const ContainerPtr& p)
_out << "\n";
string metadata, deprecateReason;
- start("blockquote");
if((*q)->findMetaData("deprecate", metadata))
{
deprecateReason = "This type is deprecated.";
if(metadata.find("deprecate:") == 0 && metadata.size() > 10)
{
- deprecateReason = metadata.substr(10);
+ deprecateReason = "_" + trim(metadata.substr(10)) + "_";
}
}
printComment(*q, p, deprecateReason, true);
- end();
}
_out << "\n{ztop}\n";
}
@@ -2558,7 +2566,7 @@ Slice::ExceptionGenerator::generate(const ExceptionPtr& e)
deprecateReason = "This module is deprecated.";
if(metadata.find("deprecate:") == 0 && metadata.size() > 10)
{
- deprecateReason = metadata.substr(10);
+ deprecateReason = "_" + trim(metadata.substr(10)) + "_";
}
}
@@ -2615,6 +2623,7 @@ Slice::ExceptionGenerator::generate(const ExceptionPtr& e)
}
}
end();
+ _out << "\n{ztop}\n";
}
if(!dataMembers.empty())
@@ -2625,7 +2634,7 @@ Slice::ExceptionGenerator::generate(const ExceptionPtr& e)
start("p");
for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q)
{
- start("tt");
+ start("h3");
printMetaData(*q);
TypePtr type = (*q)->type();
_out << toString(type, e) << " " << trim(toString(*q, e)) << ";";
@@ -2634,7 +2643,6 @@ Slice::ExceptionGenerator::generate(const ExceptionPtr& e)
string reason;
metadata.clear();
- start("blockquote");
if(deprecatedException || (*q)->findMetaData("deprecate", metadata))
{
reason = "This member is deprecated.";
@@ -2644,11 +2652,12 @@ Slice::ExceptionGenerator::generate(const ExceptionPtr& e)
}
}
printComment(*q, e, reason);
- end();
}
end();
+ _out << "\n{ztop}\n";
}
+
start("hr");
end();
printHeaderFooter(e);
@@ -2689,7 +2698,7 @@ Slice::ClassGenerator::generate(const ClassDefPtr& c)
deprecateReason += " is deprecated.";
if(metadata.find("deprecate:") == 0 && metadata.size() > 10)
{
- deprecateReason = metadata.substr(10);
+ deprecateReason = "_" + trim(metadata.substr(10)) + "_";
}
}
@@ -2755,6 +2764,7 @@ Slice::ClassGenerator::generate(const ClassDefPtr& c)
}
}
end();
+ _out << "\n{ztop}\n";
}
DataMemberList dataMembers = c->dataMembers();
@@ -2784,6 +2794,7 @@ Slice::ClassGenerator::generate(const ClassDefPtr& c)
}
}
end();
+ _out << "\n{ztop}\n";
}
if(!operations.empty())
@@ -2793,7 +2804,6 @@ Slice::ClassGenerator::generate(const ClassDefPtr& c)
end();
for(OperationList::const_iterator q = operations.begin(); q != operations.end(); ++q)
{
-// start("panel");
start("h3", "Synopsis");
TypePtr returnType = (*q)->returnType();
_out << (returnType ? toString(returnType, c, false) : string("void")) << " "
@@ -2837,12 +2847,13 @@ Slice::ClassGenerator::generate(const ClassDefPtr& c)
reason = "This operation is deprecated.";
if(metadata.find("deprecate:") == 0 && metadata.size() > 10)
{
- reason = metadata.substr(10);
+ reason = "_" + metadata.substr(10) + "_";
}
}
printComment(*q, c, reason);
-// end();//panel
}
+
+ _out << "\n{ztop}\n";
}
if(!dataMembers.empty())
@@ -2853,7 +2864,7 @@ Slice::ClassGenerator::generate(const ClassDefPtr& c)
start("p");
for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q)
{
- start("tt");
+ start("h3");
printMetaData(*q);
TypePtr type = (*q)->type();
_out << toString(type, c, false) << " " << trim(toString(*q, c)) << ";";
@@ -2862,7 +2873,6 @@ Slice::ClassGenerator::generate(const ClassDefPtr& c)
string reason;
metadata.clear();
- start("blockquote");
if(deprecatedClass || (*q)->findMetaData("deprecate", metadata))
{
reason = "This member is deprecated.";
@@ -2872,9 +2882,9 @@ Slice::ClassGenerator::generate(const ClassDefPtr& c)
}
}
printComment(*q, c, reason);
- end();
}
end();
+ _out << "\n{ztop}\n";
}
start("hr");
@@ -2915,7 +2925,7 @@ Slice::StructGenerator::generate(const StructPtr& s)
deprecateReason = "This module is deprecated.";
if(metadata.find("deprecate:") == 0 && metadata.size() > 10)
{
- deprecateReason = metadata.substr(10);
+ deprecateReason = "_" + trim(metadata.substr(10)) + "_";
}
}
@@ -2961,6 +2971,7 @@ Slice::StructGenerator::generate(const StructPtr& s)
}
}
end();
+ _out << "\n{ztop}\n";
}
if(!dataMembers.empty())
@@ -2971,7 +2982,7 @@ Slice::StructGenerator::generate(const StructPtr& s)
start("p");
for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q)
{
- start("tt");
+ start("h3");
printMetaData(*q);
TypePtr type = (*q)->type();
_out << toString(type, s, false) << " " << trim(toString(*q, s)) << ";";
@@ -2980,7 +2991,6 @@ Slice::StructGenerator::generate(const StructPtr& s)
string reason;
metadata.clear();
- start("blockquote");
if(deprecatedException || (*q)->findMetaData("deprecate", metadata))
{
reason = "This member is deprecated.";
@@ -2990,9 +3000,9 @@ Slice::StructGenerator::generate(const StructPtr& s)
}
}
printComment(*q, s, reason);
- end();
}
end();
+ _out << "\n{ztop}\n";
}
start("hr");
@@ -3033,7 +3043,7 @@ Slice::EnumGenerator::generate(const EnumPtr& e)
deprecateReason = "This enumeration is deprecated.";
if(metadata.find("deprecate:") == 0 && metadata.size() > 10)
{
- deprecateReason = metadata.substr(10);
+ deprecateReason = "_" + trim(metadata.substr(10)) + "_";
}
}
@@ -3074,6 +3084,7 @@ Slice::EnumGenerator::generate(const EnumPtr& e)
end();
}
end();
+ _out << "\n{ztop}\n";
}
closeDoc();