| 1 |
/* |
| 2 |
* This file is part of MUSIC. |
| 3 |
* Copyright (C) 2008, 2009 INCF |
| 4 |
* |
| 5 |
* MUSIC is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 3 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* MUSIC is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
#include <cstdio> |
| 20 |
|
| 21 |
#include "music/ioutils.hh" |
| 22 |
|
| 23 |
namespace MUSIC { |
| 24 |
|
| 25 |
namespace IOUtils { |
| 26 |
|
| 27 |
void |
| 28 |
write (std::ostringstream& out, std::string s) |
| 29 |
{ |
| 30 |
std::istringstream value (s); |
| 31 |
while (true) |
| 32 |
{ |
| 33 |
int c; |
| 34 |
switch (c = value.get ()) |
| 35 |
{ |
| 36 |
case '\\': |
| 37 |
case ':': |
| 38 |
out << '\\'; |
| 39 |
default: |
| 40 |
out << (char) c; |
| 41 |
continue; |
| 42 |
case EOF: |
| 43 |
break; |
| 44 |
} |
| 45 |
break; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
std::string |
| 51 |
read (std::istringstream& in, int delim) |
| 52 |
{ |
| 53 |
std::ostringstream value; |
| 54 |
while (true) |
| 55 |
{ |
| 56 |
int c = in.peek (); |
| 57 |
switch (c) |
| 58 |
{ |
| 59 |
case '\\': |
| 60 |
in.get (); |
| 61 |
value << (char) in.get (); |
| 62 |
continue; |
| 63 |
default: |
| 64 |
if (c == delim) |
| 65 |
break; |
| 66 |
value << (char) in.get (); |
| 67 |
continue; |
| 68 |
case EOF: |
| 69 |
break; |
| 70 |
} |
| 71 |
break; |
| 72 |
} |
| 73 |
return value.str (); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
std::string |
| 78 |
read (std::istringstream& in) |
| 79 |
{ |
| 80 |
return read (in, ':'); |
| 81 |
} |
| 82 |
|
| 83 |
} |
| 84 |
|
| 85 |
} |