From: Foster B. <fos...@us...> - 2006-01-06 18:36:08
|
Update of /cvsroot/adobe-source/adobe-source/adobe/test/begin/headers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12808/adobe/test/begin/headers Modified Files: express_viewer.hpp latch.hpp report_exception.hpp Log Message: asl 1.0.12 Index: latch.hpp =================================================================== RCS file: /cvsroot/adobe-source/adobe-source/adobe/test/begin/headers/latch.hpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** latch.hpp 2 Dec 2005 02:52:56 -0000 1.2 --- latch.hpp 6 Jan 2006 18:35:23 -0000 1.3 *************** *** 1,8 **** /* ! Copyright 2005 Adobe Systems Incorporated Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt or a copy at http://opensource.adobe.com/licenses.html) */ ! #include <adobe/config.hpp> /****************************************************************************************************/ --- 1,8 ---- /* ! Copyright 2005-2006 Adobe Systems Incorporated Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt or a copy at http://opensource.adobe.com/licenses.html) */ ! /****************************************************************************************************/ *************** *** 12,15 **** --- 12,17 ---- /****************************************************************************************************/ + #include <adobe/config.hpp> + #include <adobe/dictionary.hpp> #include <adobe/value.hpp> Index: report_exception.hpp =================================================================== RCS file: /cvsroot/adobe-source/adobe-source/adobe/test/begin/headers/report_exception.hpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** report_exception.hpp 2 Dec 2005 02:52:56 -0000 1.2 --- report_exception.hpp 6 Jan 2006 18:35:23 -0000 1.3 *************** *** 1,8 **** /* ! Copyright 2005 Adobe Systems Incorporated Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt or a copy at http://opensource.adobe.com/licenses.html) */ ! #include <adobe/config.hpp> /****************************************************************************************************/ --- 1,8 ---- /* ! Copyright 2005-2006 Adobe Systems Incorporated Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt or a copy at http://opensource.adobe.com/licenses.html) */ ! /****************************************************************************************************/ *************** *** 12,15 **** --- 12,17 ---- /****************************************************************************************************/ + #include <adobe/config.hpp> + #include <iostream> #include <fstream> Index: express_viewer.hpp =================================================================== RCS file: /cvsroot/adobe-source/adobe-source/adobe/test/begin/headers/express_viewer.hpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** express_viewer.hpp 2 Dec 2005 02:52:56 -0000 1.5 --- express_viewer.hpp 6 Jan 2006 18:35:23 -0000 1.6 *************** *** 11,14 **** --- 11,15 ---- #include <adobe/config.hpp> + #include <adobe/adam.hpp> #include <adobe/future/file_slurp.hpp> *************** *** 45,49 **** /* REVISIT (sparent) : The lf handling should be moved down into where ever this data is going - ! In this case into a UI widget. The general rool should everything should be agnostic about line endings on read. And everything should write Unix style (just '\n') line endings. */ --- 46,50 ---- /* REVISIT (sparent) : The lf handling should be moved down into where ever this data is going - ! In this case into a UI widget. The general rule should everything should be agnostic about line endings on read. And everything should write Unix style (just '\n') line endings. */ *************** *** 85,93 **** // REVISIT (fbrereto) : This is all a hack. Get notifiers in here instead of as_string and the like. ! struct file_buffer_t { public: typedef boost::function<void (bool)> dirty_proc_t; void set_path(const boost::filesystem::path& path) { --- 86,108 ---- // REVISIT (fbrereto) : This is all a hack. Get notifiers in here instead of as_string and the like. ! class file_buffer_t { public: + enum line_ending_t + { + line_ending_unknown_k = 0, + line_ending_platform_k = 1 << 0L, + line_ending_unix_k = 1 << 1L, // LF + line_ending_windows_k = 1 << 2L, // CR+LF + line_ending_mac_os_classic_k = 1 << 3L, // CR + line_ending_mac_os_x_k = line_ending_unix_k // LF + }; + typedef boost::function<void (bool)> dirty_proc_t; + file_buffer_t() : + le_m(line_ending_unknown_k) + { } + void set_path(const boost::filesystem::path& path) { *************** *** 98,101 **** --- 113,118 ---- contents_m.assign(slurp.begin(), slurp.end()); + set_line_endings_impl(le_m, true); + set_dirty(false); } *************** *** 109,117 **** } void save() { if (!dirty_m) return; ! bfs::ofstream output( path_m ); // --- 126,141 ---- } + inline void set_line_endings(line_ending_t le, bool force = false) + { + set_line_endings_impl(le, force); + + set_dirty(true); + } + void save() { if (!dirty_m) return; ! bfs::ofstream output( path_m, std::ios_base::out | std::ios_base::binary ); // *************** *** 123,131 **** + path_m.string() + "\"" ); ! std::string filtered( contents_m ); ! ! adobe::replace( filtered, '\r', '\n' ); ! output << filtered; set_dirty(false); --- 147,154 ---- + path_m.string() + "\"" ); ! if (le_m == line_ending_unknown_k) ! set_line_endings(le_m); ! output << contents_m; set_dirty(false); *************** *** 141,145 **** { if (dirty_m) ! return "in-memory contents"; else return path_m.string().c_str(); --- 164,168 ---- { if (dirty_m) ! return "(temporary file buffer)"; else return path_m.string().c_str(); *************** *** 164,175 **** --- 187,267 ---- } + void replace_all(const char* src, const char* dst) + { + // replaces all instances of src with dst + + std::string::size_type result(0); + std::size_t src_n(std::strlen(src)); + std::size_t dst_n(std::strlen(dst)); + + while (true) + { + result = contents_m.find(src, result); + + if (result == std::string::npos) break; + + contents_m.replace(result, src_n, dst, dst_n); + + result += dst_n; + } + } + + void set_line_endings_impl(line_ending_t le, bool force = false) + { + if (le_m == le && !force && + le_m != line_ending_unknown_k) return; + + if (le == line_ending_platform_k || le == line_ending_unknown_k) + { + #if ADOBE_PLATFORM_WIN + le_m = line_ending_windows_k; + #else + le_m = line_ending_unix_k; + #endif + } + else + { + le_m = le; + } + + // REVISIT (fbrereto) : Not as optimal as it could be. + + if (le_m == line_ending_unix_k) + { + replace_all("\r\n", "\n"); + replace_all("\r", "\n"); + } + else if (le_m == line_ending_windows_k) + { + replace_all("\r\n", "\n"); + replace_all("\r", "\n"); + replace_all("\n", "\r\n"); + } + else if (le_m == line_ending_mac_os_classic_k) + { + replace_all("\r\n", "\r"); + replace_all("\n", "\r"); + } + else + throw std::runtime_error("unknown line ending type"); + + // set line endings back to 'unknown' if + // that's what they were originally + if (le == line_ending_unknown_k) le_m = line_ending_unknown_k; + } + bfs::path path_m; ///< Path to the current file std::string contents_m; ///< Contents of the file (not necessarily same as that in file) bool dirty_m; ///< Dirty bit dirty_proc_t dirty_proc_m; ///< Dirty bit modification notifier + line_ending_t le_m; ///< Line ending flags }; /****************************************************************************************************/ + ADOBE_DEFINE_BITSET_OPS(file_buffer_t::line_ending_t) + + /****************************************************************************************************/ + // /// The application_t class is implemented in express_viewer.cpp and defines |