Fresco/Fresco-C++/src Unicode.cc,1.8,1.9

Tobias Hunger <[email protected]> Fri, 01 Aug 2003 11:47:52 -0500
Newsgroups gmane.comp.video.fresco.cvs
Message-ID <[email protected]>
Update of /cvs/fresco/Fresco/Fresco-C++/src
In directory purcel:/tmp/cvs-serv24256/Fresco-C++/src

Modified Files:
	Unicode.cc 
Log Message:
Babylon work over:
 * Use iconv to convert characters to/from Babylon
 * Updtae to Unicode Version 4.0
 * Added unit tests (some fail for now, still need to work on that)

 * Removed the VisualTextBuffer from the CommandKit: I still like the idea,
   unfortunately it won't work out in the real world:-|

 * Updated code to the changed Babylon interfaces whereever needed.


Index: Unicode.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Fresco-C++/src/Unicode.cc,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- Unicode.cc	12 Jun 2002 20:39:35 -0000	1.8
+++ Unicode.cc	1 Aug 2003 16:47:20 -0000	1.9
@@ -1,7 +1,7 @@
 /*$Id Unicode.cc,v 1.6 2002/05/29 06:49:41 stefan Exp $
  *
  * This source file is a part of the Fresco Project.
- * Copyright (C) 1999 Tobias Hunger <[email protected]>
+ * Copyright (C) 1999-2003 Tobias Hunger <[email protected]>
  * http://www.fresco.org
  *
  * This library is free software; you can redistribute it and/or
@@ -24,32 +24,39 @@
 // the Unistring (defined in Warsaw) that CORBA needs.
 
 #include <Fresco/Unicode.hh>
+#include <Babylon/internal/utfstrings.hh>
 
 using namespace Fresco;
 
 // This is ugly but necessary since Unistring does not
-// know iterators! So I can“t do decent assigment
+// know iterators! So I can't do decent assigment
 // operators :-(
 
-Unistring Unicode::to_CORBA(const Babylon::String &s) {
-  Babylon::UTF16_string tmp = s.utf16();
-  Fresco::Unistring res(tmp.length(),
-			tmp.length(),
-			const_cast<Babylon::UCS2 *>(tmp.data()));
-  return res;
+Unistring Unicode::to_CORBA(const Babylon::String &s)
+{
+    std::string tmp = s.convert(Babylon::UTF16_format);
+    const Babylon::UCS2 * ucs2str =
+	reinterpret_cast<const Babylon::UCS2 *>(tmp.data());
+    // Don't copy, don't release:
+    Fresco::Unistring res(tmp.length() / 2, tmp.length() / 2,
+			  const_cast<Babylon::UCS2 *>(ucs2str), 0);
+    return res;
 }
 
-Fresco::Unichar Unicode::to_CORBA(const Babylon::Char c) {
+Fresco::Unichar Unicode::to_CORBA(const Babylon::Char c)
+{
     return Fresco::Unichar(c.value());
 }
 
-Babylon::String Unicode::to_internal(const Unistring & us) {
-    Babylon::String res;
-    for (size_t i = 0; i < us.length(); ++i)
-      res.push_back(Babylon::Char(static_cast<const Babylon::UCS2>(us[i])));
+Babylon::String Unicode::to_internal(const Unistring & us)
+{
+    std::string tmp(reinterpret_cast<const char *>(us.get_buffer()),
+		    us.length() * 2);
+    Babylon::String res(tmp, 0, Babylon::UTF16_format);
     return res;
 }
 
-Babylon::Char Unicode::to_internal(const Fresco::Unichar uc) {
+Babylon::Char Unicode::to_internal(const Fresco::Unichar uc)
+{
     return Babylon::Char(Babylon::UCS4(uc));
 }