Changeset c1e2243fb1d931f43be26b3abfe1be8be0f52c33
- Timestamp:
- 01/06/07 23:47:18 (6 years ago)
- Author:
- Philipp Kern <phil@…>
- Parents:
- b3345157b2b819cd58281cee08c90aa8d9bf309e
- Children:
- 71a982926069e42fa9bb0f8d38b1d6d4d82c527d
- git-committer:
- Philipp Kern <phil@0x539.de> / 2007-01-06T22:47:18Z+0000
- Message:
-
[project @ Convert all different line encodings to UNIX ones]
Original author: Philipp Kern <phil@…>
Date: 2005-09-04 21:29:39+00:00
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r5960b6c
|
rc1e2243
|
|
| 831 | 831 | } |
| 832 | 832 | |
| | 833 | namespace |
| | 834 | { |
| | 835 | // convert2unix converts a given string from any special line endings |
| | 836 | // (DOS or old-style Macintosh) to Unix line endings. It does no |
| | 837 | // book-keeping about the encountered endings but ensures that no |
| | 838 | // CR characters are left in the string. |
| | 839 | void convert2unix(std::string& str) |
| | 840 | { |
| | 841 | for(std::string::size_type i = 0; i < str.length(); ++ i) |
| | 842 | // Convert DOS CRLF to a single LF |
| | 843 | if(str[i] == '\r' && str[i+1] == '\n') |
| | 844 | str.erase(i, 1); |
| | 845 | // Convert Macintosh CR to LF |
| | 846 | else if(str[i] == '\r') |
| | 847 | str[i] = '\n'; |
| | 848 | } |
| | 849 | } |
| | 850 | |
| 833 | 851 | void Gobby::Window::open_local_file(const Glib::ustring& file, |
| 834 | 852 | bool open_as_edited) |
| … |
… |
|
| 838 | 856 | // Set local file path for the document_insert callback |
| 839 | 857 | m_local_file_path = file; |
| | 858 | std::string content( |
| | 859 | convert_to_utf8(Glib::file_get_contents(file)) ); |
| | 860 | convert2unix(content); |
| 840 | 861 | |
| 841 | 862 | // TODO: Set path in newly generated document |
| 842 | 863 | // TODO: Convert file to UTF-8 |
| 843 | 864 | m_buffer->create_document( |
| 844 | | Glib::path_get_basename(file), |
| 845 | | convert_to_utf8(Glib::file_get_contents(file)), |
| 846 | | open_as_edited |
| | 865 | Glib::path_get_basename(file), content, open_as_edited |
| 847 | 866 | ); |
| 848 | 867 | } |