1 /*
2 
3   Lyrics3 input/output
4 
5   copyright (c) 2006 squell <squell@alumina.nl>
6 
7   use, modification, copying and distribution of this software is permitted
8   under the conditions described in the file 'COPYING'.
9 
10   Usage:
11 
12   - lyrics3::field(id, content)
13   Returns a Lyrics3 'ID' field containing 'content', or empty if invalid
14 
15   - lyrics3::find(tag, id)
16   Returns the content of the 'ID' field of 'tag', or empty if not found
17 
18   - lyrics3::read(file[, id3v1buf])
19   Returns the Lyrics3 tag of 'file', or empty if none. if id3v1buf != NULL,
20   stores a found id3v1 tag there, or a null byte if none.
21 
22   - lyrics3::cast(string)
23   IF string is a valid Lyrics3 tag, returns it, otherwise empty
24 
25   - lyrics3::write(file, tag[, id3v1buf])
26   Writes the Lyrics3 'tag' to 'file'. Returns 0 on success, non-zero on
27   failure, and negative in case of a serious write error.
28 
29   - lyrics3::find_next(tag, cur[, id3v1buf])
30   Returns the end position of a Lyrics3 frame in 'tag', or 0 if already ended
31 
32   - lyrics3::info
33   Restricted string. Added members: str(), id(i), content(i[,next])
34 
35   Example:
36 
37     lyrics3::info tag = lyrics3::read("foo.mp3");
38     for(long n, i = 0; n=lyrics3::find_next(tag,i); i = n)
39         std::cout << tag.id(i) << ": " << tag.content(i,n) << std::endl;
40 
41 */
42 #ifndef __ZF_LYRICS3_HPP
43 #define __ZF_LYRICS3_HPP
44 
45 #include <string>
46 #include <iterator>
47 
48 namespace lyrics3 {
49 
50     class info : std::string {
51     public:
52         friend info field(const std::string& id,  const std::string& content);
53         friend info cast (const std::string&);
54         friend info read (const char* fn, void* id3);
55         friend int  write(const char* fn, const info& tag, const void* newid3);
56 
57         friend std::string     find     (const info& s, const std::string& sig);
58         friend info::size_type find_next(const info& s, info::size_type pos);
59         friend info field(const std::string& s);
60 
61         info& operator+=(const info& other)
62         { return std::string::operator+=(other), *this; }
63         friend info operator+(info lhs, const info& rhs)
64         { return lhs += rhs; }
65 
str()66         const std::string& str() const { return *this; }
67         using std::string::size;
68         using std::string::c_str;
69 
id(size_type i)70         std::string id(size_type i) const
71         { return substr(i, 3); }
content(size_type i,size_type n)72         std::string content(size_type i, size_type n) const
73         { return substr(i+8, n-i-8); }
content(size_type i)74         std::string content(size_type i) const
75         { return substr(i+8, find_next(*this, i)-i-8); }
info()76         info() { }
77 
78         class iterator;
79     private:
info(const std::string & s)80         info(const std::string& s) : std::string(s) { }
81     };
82 
83     info field(const std::string& id,  const std::string& content);
84     info cast (const std::string&);
85     info read (const char* fn, void* id3 = 0);
86     int  write(const char* fn, const info& tag, const void* newid3 = 0);
87 
88     std::string     find     (const info& s, const std::string& sig);
89     info::size_type find_next(const info& s, info::size_type pos);
90     info field(const std::string& s);
91 }
92 
93 #endif
94 
95