Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmDocumentationFormatter.cxx
blobdf04675dfa7f4e010bf7ec94278fc76d742c783e
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmDocumentationFormatter.cxx,v $
5 Language: C++
6 Date: $Date: 2008-10-10 15:23:35 $
7 Version: $Revision: 1.4 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmDocumentationFormatter.h"
19 cmDocumentationFormatter::cmDocumentationFormatter()
23 cmDocumentationFormatter::~cmDocumentationFormatter()
27 void cmDocumentationFormatter::PrintFormatted(std::ostream& os,
28 const char* text)
30 if(!text)
32 return;
34 const char* ptr = text;
35 while(*ptr)
37 // Any ptrs starting in a space are treated as preformatted text.
38 std::string preformatted;
39 while(*ptr == ' ')
41 for(char ch = *ptr; ch && ch != '\n'; ++ptr, ch = *ptr)
43 preformatted.append(1, ch);
45 if(*ptr)
47 ++ptr;
48 preformatted.append(1, '\n');
51 if(preformatted.length())
53 this->PrintPreformatted(os, preformatted.c_str());
56 // Other ptrs are treated as paragraphs.
57 std::string paragraph;
58 for(char ch = *ptr; ch && ch != '\n'; ++ptr, ch = *ptr)
60 paragraph.append(1, ch);
62 if(*ptr)
64 ++ptr;
65 paragraph.append(1, '\n');
67 if(paragraph.length())
69 this->PrintParagraph(os, paragraph.c_str());
74 //----------------------------------------------------------------------------
75 std::string
76 cmDocumentationFormatter::ComputeSectionLinkPrefix(std::string const& name)
78 // Map from section name to a prefix for links pointing within the
79 // section. For example, the commands section should have HTML
80 // links to each command with names like #command:ADD_EXECUTABLE.
81 if(name.find("Command") != name.npos)
83 return "command";
85 else if(name.find("Propert") != name.npos)
87 if(name.find("Global") != name.npos)
89 return "prop_global";
91 else if(name.find("Direct") != name.npos)
93 return "prop_dir";
95 else if(name.find("Target") != name.npos)
97 return "prop_tgt";
99 else if(name.find("Test") != name.npos)
101 return "prop_test";
103 else if(name.find("Source") != name.npos)
105 return "prop_sf";
107 return "property";
109 else if(name.find("Variable") != name.npos)
111 return "variable";
113 else if(name.find("Polic") != name.npos)
115 return "policy";
117 else if(name.find("Module") != name.npos)
119 return "module";
121 else if(name.find("Name") != name.npos ||
122 name.find("Introduction") != name.npos)
124 return "name";
126 else if(name.find("Usage") != name.npos)
128 return "usage";
130 else if(name.find("Description") != name.npos)
132 return "desc";
134 else if(name.find("Generators") != name.npos)
136 return "gen";
138 else if(name.find("Options") != name.npos)
140 return "opt";
142 else if(name.find("Copyright") != name.npos)
144 return "copy";
146 else if(name.find("See Also") != name.npos)
148 return "see";
150 else if(name.find("SingleItem") != name.npos)
152 return "single_item";
154 else
156 std::cerr
157 << "WARNING: ComputeSectionLinkPrefix failed for \"" << name << "\""
158 << std::endl;
159 return "other";