changeset 47:be19b235c6c4

implement PreferenceStore.store
author Frank Benoit <benoit@tionex.de>
date Fri, 11 Apr 2008 16:19:36 +0200
parents 9d7d88f13040
children 7a3e6c1a4eae
files dwtx/jface/preference/PreferenceStore.d
diffstat 1 files changed, 42 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/dwtx/jface/preference/PreferenceStore.d	Fri Apr 11 16:19:01 2008 +0200
+++ b/dwtx/jface/preference/PreferenceStore.d	Fri Apr 11 16:19:36 2008 +0200
@@ -113,7 +113,7 @@
                         case 't': c = '\t'; break;
                         case 'n': c = '\n'; break;
                         case '\\': c = '\\'; break;
-                        default:  c = '?'; break;
+                        default:  break;
                         }
                     }
                     else{
@@ -153,8 +153,45 @@
             }
         }
 
-        public synchronized void store( OutputStream out_, String comments ){
-            implMissing( __FILE__, __LINE__ );
+        public synchronized void store( OutputStream ostr, String comments ){
+            void append(char[] s){
+                foreach( c; s ){
+                    switch( c ){
+                    case '\t': ostr.write( "\\t"  ); break;
+                    case '\n': ostr.write( "\\n"  ); break;
+                    case '\r': ostr.write( "\\r"  ); break;
+                    case '\\': ostr.write( "\\\\" ); break;
+                    case ':' : ostr.write( "\\:"  ); break;
+                    default: {
+                            char[1] b;
+                            b[0] = c;
+                            ostr.write( b ); break;
+                        }
+                    }
+                }
+            }
+            if( comments.length ){
+                bool lineStart = true;
+                for( int idx = 0; idx < comments.length; idx++ ){
+                    char[1] b;
+                    if( lineStart ){
+                        b[0] = '#';
+                        ostr.write(b);
+                    }
+                    append( comments[ idx .. idx+1 ] );
+                    lineStart = false;
+                    if( comments[idx] is '\n' ){
+                        lineStart = true;
+                    }
+                }
+                ostr.write( "\n" );
+            }
+            foreach( k, v; map ){
+                append(k);
+                append("=");
+                append(v);
+                ostr.write( "\n" );
+            }
         }
 
 //         public synchronized void save( dejavu.io.OutputStream.OutputStream out_KEYWORDESCAPE, dejavu.lang.String.String comments ){
@@ -918,7 +955,8 @@
      * @param value
      */
     private void setValue(Properties p, String name, String value) {
-        Assert.isTrue(p !is null && value !is null);
+        // DWT: allow null value
+        Assert.isTrue(p !is null /+&& value !is null+/);
         p.put(name, value);
     }