]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetHyperlink.cpp
* Inset: Prepare for an eventual merge of updateLabels() and addToToc()
[lyx.git] / src / insets / InsetHyperlink.cpp
index 74f6a05514985f3f3ecbb1d6725e6ec3e4813b6f..908ddd1337c099e35bfc2b97cb58a427ebf0e4e5 100644 (file)
 #include "DispatchResult.h"
 #include "FuncRequest.h"
 #include "LaTeXFeatures.h"
-#include "gettext.h"
+#include "support/gettext.h"
 #include "OutputParams.h"
 
 #include "support/lstrings.h"
 #include "support/docstream.h"
 
+using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 
-using support::subst;
-
-using std::string;
-using std::find;
-using std::replace;
-
-static char_type const chars_url[2] = {'%', '#'};
-
-static char_type const chars_name[6] = {
-       '&', '_', '$', '%', '#', '^'};
-
 
 InsetHyperlink::InsetHyperlink(InsetCommandParams const & p)
        : InsetCommand(p, "href")
@@ -75,8 +66,11 @@ int InsetHyperlink::latex(Buffer const &, odocstream & os,
                    OutputParams const & runparams) const
 {
        docstring url = getParam("target");
-       docstring backslash = from_ascii("\\");
-       docstring braces = from_ascii("{}");
+       static docstring const backslash = from_ascii("\\");
+       static docstring const braces = from_ascii("{}");
+       static char_type const chars_url[2] = {'%', '#'};
+       static char_type const chars_name[6] = {
+               '&', '_', '$', '%', '#', '^'};
 
        // The characters in chars_url[] need to be changed to a command when
        // they are in the url field.
@@ -99,11 +93,11 @@ int InsetHyperlink::latex(Buffer const &, odocstream & os,
 
                // handle the "\" character, but only when the following character
                // is not also a "\", because "\\" is valid code
-               docstring textbackslash = from_ascii("\\textbackslash{}");
+               docstring const textbackslash = from_ascii("\\textbackslash{}");
                for (size_t i = 0, pos;
                        (pos = name.find('\\', i)) != string::npos;
                        i = pos + 2) {
-                       if      (name[pos + 1] != '\\')
+                       if (name[pos + 1] != '\\')
                                name.replace(pos, 1, textbackslash);
                }
                for (int k = 0; k < 6; k++) {
@@ -115,26 +109,21 @@ int InsetHyperlink::latex(Buffer const &, odocstream & os,
                }
                // replace the tilde by the \sim character as suggested in the LaTeX FAQ
                // for URLs
-               docstring sim = from_ascii("$\\sim$");
-               for (int i = 0, pos;
+               docstring const sim = from_ascii("$\\sim$");
+               for (size_t i = 0, pos;
                        (pos = name.find('~', i)) != string::npos;
                        i = pos + 1)
                        name.replace(pos, 1, sim);
 
        }  // end if (!name.empty())
        
-       //for the case there is no name given, the target is set as name
-       docstring urlname = url;
-       // set the hyperlink type
-       url += getParam("type");
-
        if (runparams.moving_arg)
                os << "\\protect";
-       //set the target for the name when no name is given
-       if (!name.empty())
-               os << "\\href{" << url << "}{" << name << '}';
-       else
-               os << "\\href{" << url << "}{" << urlname << '}';
+
+       //for the case there is no name given, the target is set as name
+       os << "\\href{" << getParam("type") << url << "}{"
+               << (name.empty()? url : name) << '}';
+
        return 0;
 }
 
@@ -168,10 +157,9 @@ int InsetHyperlink::docbook(Buffer const &, odocstream & os,
 }
 
 
-int InsetHyperlink::textString(Buffer const & buf, odocstream & os,
-                      OutputParams const & op) const
+void InsetHyperlink::textString(Buffer const & buf, odocstream & os) const
 {
-       return plaintext(buf, os, op);
+       plaintext(buf, os, OutputParams(0));
 }