]> git.tdb.fi Git - libs/core.git/blobdiff - source/stringcodec/codecutils.cpp
Move files around to prepare for assimilation into core
[libs/core.git] / source / stringcodec / codecutils.cpp
diff --git a/source/stringcodec/codecutils.cpp b/source/stringcodec/codecutils.cpp
new file mode 100644 (file)
index 0000000..6afbf95
--- /dev/null
@@ -0,0 +1,27 @@
+/* $Id$
+
+This file is part of libmspstrings
+Copyright © 2006-2007 Mikko Rasa
+Distributed under the LGPL
+*/
+
+#include "codecutils.h"
+
+namespace Msp {
+namespace Codecs {
+
+int transform_mapping_or_direct(const int *mapping, unsigned map_size, int ch, bool reverse)
+{
+       for(unsigned i=0; i<map_size*2; i+=2)
+       {
+               if(mapping[i+reverse]==ch)
+                       return mapping[i+1-reverse];
+               else if(mapping[i+1-reverse]==ch)
+                       return -1;
+       }
+
+       return ch;
+}
+
+} // namespace Codecs
+} // namespace Msp