]> git.lyx.org Git - lyx.git/blobdiff - src/chset.h
A better fix for bug 675:
[lyx.git] / src / chset.h
index f32fb9b047cb08242a58b8b865cd132335346c3a..6b92092838641f40057cd6a311c9169184bfd72f 100644 (file)
@@ -1,44 +1,55 @@
 // -*- C++ -*-
-#ifndef _Chset_h_
-#define _Chset_h_
+/**
+ * \file chset.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Lars Gullik Bjønnes
+ * \author Jean-Marc Lasgouttes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
 
-#ifdef __GNUG__
-#pragma interface
-#endif
+#ifndef CHSET_H
+#define CHSET_H
+
+#include <map>
+#include <utility>
+#include <string>
 
-#include "LString.h"
 
-///
+namespace lyx {
+
+/// a class for mapping char strings such as "\^{A}" to the integer value
 class CharacterSet {
 public:
-       ///
-       CharacterSet();
-       ///
-       ~CharacterSet();
-       
-       ///
-       bool loadFile(const string&);
-       ///
-       string getName();
-       ///
-       bool encodeString(string&);
+       /**
+        * initialise this charset from the given .cdef file
+        * param charset the charset to look for
+        *
+        * Finds a .cdef file corresponding to the named charset
+        * and parses it. This function is only intended to be
+        * called once.
+        */
+       bool loadFile(std::string const & charset);
+       /// return the name of the current charset
+       std::string const & getName() const;
+       /**
+        * Return the encoded charset value of the given string.
+        *
+        * The bool value is false if an encoding could not be found
+        * in this charset, and true otherwise.
+        */
+       std::pair<bool, int> const encodeString(std::string const &) const;
 private:
+       /// charset name
+       std::string name_;
        ///
-       string name_;
-       
-       ///
-       struct Cdef {
-               ///
-               unsigned char ic;
-               ///
-               string str;
-               ///
-               Cdef *next;
-       };
-       
-       ///
-       Cdef *map_;
-       ///
-       void freeMap();
+       typedef std::map<std::string, unsigned char> Cdef;
+       /// mapping from string representation to encoded value
+       Cdef map_;
 };
+
+} // namespace lyx
+
 #endif