Chris@629
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@629
|
2
|
Chris@629
|
3 /*
|
Chris@629
|
4 Sonic Visualiser
|
Chris@629
|
5 An audio file viewer and annotation editor.
|
Chris@629
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@629
|
7
|
Chris@629
|
8 This program is free software; you can redistribute it and/or
|
Chris@629
|
9 modify it under the terms of the GNU General Public License as
|
Chris@629
|
10 published by the Free Software Foundation; either version 2 of the
|
Chris@629
|
11 License, or (at your option) any later version. See the file
|
Chris@629
|
12 COPYING included with this distribution for more information.
|
Chris@629
|
13 */
|
Chris@629
|
14
|
Chris@629
|
15 /*
|
Chris@629
|
16 This is a modified version of a source file from the
|
Chris@629
|
17 Rosegarden MIDI and audio sequencer and notation editor.
|
Chris@629
|
18 This file copyright 2000-2010 Chris Cannam.
|
Chris@629
|
19 */
|
Chris@629
|
20
|
Chris@1524
|
21 #ifndef SV_STRING_BITS_H
|
Chris@1524
|
22 #define SV_STRING_BITS_H
|
Chris@629
|
23
|
Chris@629
|
24 #include <QString>
|
Chris@629
|
25 #include <QStringList>
|
Chris@629
|
26 #include <QChar>
|
Chris@629
|
27
|
Chris@629
|
28 class StringBits
|
Chris@629
|
29 {
|
Chris@629
|
30 public:
|
Chris@629
|
31 /**
|
Chris@629
|
32 * Convert a string to a double using basic "C"-locale syntax,
|
Chris@629
|
33 * i.e. always using '.' as a decimal point. We use this as a
|
Chris@629
|
34 * fallback when parsing files from an unknown source, if
|
Chris@629
|
35 * locale-specific conversion fails. Does not support e notation.
|
Chris@629
|
36 * If ok is non-NULL, *ok will be set to true if conversion
|
Chris@629
|
37 * succeeds or false otherwise.
|
Chris@629
|
38 */
|
Chris@629
|
39 static double stringToDoubleLocaleFree(QString s, bool *ok = 0);
|
Chris@629
|
40
|
Chris@629
|
41 /**
|
Chris@629
|
42 * Split a string at the given separator character, allowing
|
Chris@629
|
43 * quoted sections that contain the separator. If the separator
|
Chris@629
|
44 * is ' ', any (amount of) whitespace will be considered as a
|
Chris@629
|
45 * single separator. If the separator is another whitespace
|
Chris@629
|
46 * character such as '\t', it will be used literally.
|
Chris@629
|
47 */
|
Chris@629
|
48 static QStringList splitQuoted(QString s, QChar separator);
|
Chris@629
|
49
|
Chris@629
|
50 /**
|
Chris@629
|
51 * Split a string at the given separator character. If quoted is
|
Chris@629
|
52 * true, do so by calling splitQuoted (above). If quoted is
|
Chris@629
|
53 * false, use QString::split; if separator is ' ', use
|
Chris@629
|
54 * SkipEmptyParts behaviour, otherwise use KeepEmptyParts (this is
|
Chris@629
|
55 * analogous to the behaviour of splitQuoted).
|
Chris@629
|
56 */
|
Chris@629
|
57 static QStringList split(QString s, QChar separator, bool quoted);
|
Chris@1833
|
58
|
Chris@1833
|
59 /**
|
Chris@1833
|
60 * Join a vector of strings into a single string, with the
|
Chris@1833
|
61 * delimiter as the joining string. If a string contains the
|
Chris@1833
|
62 * delimiter already, quote it with double-quotes, replacing any
|
Chris@1833
|
63 * existing double-quotes within it by a pair of double-quotes, as
|
Chris@1833
|
64 * specified in RFC 4180 Common Format and MIME Type for
|
Chris@1833
|
65 * Comma-Separated Values (CSV) Files.
|
Chris@1833
|
66 */
|
Chris@1833
|
67 static QString joinDelimited(QVector<QString> row, QString delimiter);
|
Chris@1851
|
68
|
Chris@1851
|
69 /**
|
Chris@1851
|
70 * Return true if the given byte array contains a valid UTF-8
|
Chris@1851
|
71 * sequence, false if not. If isTruncated is true, the byte array
|
Chris@1851
|
72 * will be treated as the prefix of a longer byte sequence, and
|
Chris@1851
|
73 * any errors resulting from a multibyte code ending prematurely
|
Chris@1851
|
74 * at the end of the array will be ignored.
|
Chris@1851
|
75 */
|
Chris@1851
|
76 static bool isValidUtf8(const std::string &bytes, bool isTruncated);
|
Chris@629
|
77 };
|
Chris@629
|
78
|
Chris@629
|
79 #endif
|