Skip to content

Commit

Permalink
*** empty log message ***
Browse files Browse the repository at this point in the history
  • Loading branch information
squell committed Mar 16, 2006
1 parent 693bb97 commit fd58779
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 21 deletions.
4 changes: 3 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ Changelog for 'id3'.
2006-073 (W11):
main: [CLI CHANGE] -R has been made into a simple switch which enables the
matching of '/' against wildcards.
main.cpp/set_base.h: code reorganisation
fileexp: integrated pattern() into glob()
main.cpp/set_base.h: code reorganisation
pattern.cpp: prefix gets copied now; making
`id3 -m "%+a - %||t.mp3"' equal to `id3 -a "%+1" -t "%||2" "* - *.mp3"'

2006-040 (W06):
lyrics3.cpp/getlyr3.cpp created
Expand Down
6 changes: 5 additions & 1 deletion id3.man
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,11 @@ Capitalize the substituted value
Convert all characters to lowercase
.TP
.BR _ " (underscore)
Do not replace underscores with spaces, and do not compress empty space.
Use the raw value of the variable. Normally, substitution replaces any
underscores with spaces, and condenses empty whitespace.
.TP
.BR * " (asterisk)
Split the variable into seperate words by looking at the capitalization.
.TP
.BR # " (hash\ or\ pound\ sign)
Pad all numeric values within the substituted value, if necessary.
Expand Down
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ int main_(int argc, char *argv[])

if(state & patrn) {
if(argv[i+1]) {
eprintf("-m: unexpected extraneous file arguments given\n", argv[i]);
eprintf("-m %s: no file arguments are allowed\n", argv[i]);
shelp();
}
pattern spec(tag, argpath(argv[i]));
Expand Down
2 changes: 1 addition & 1 deletion mass_tag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace fileexp {

// defining variable mapping characters <-> ID3field

ID3field mass_tag::field(char c)
ID3field mass_tag::field(wchar_t c)
{
switch(c) {
case 't': return tag::title;
Expand Down
2 changes: 1 addition & 1 deletion mass_tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace fileexp {
const tag::writer& tag_writer;
const tag::reader& tag_reader;

static tag::ID3field field(char c);
static tag::ID3field field(wchar_t c);
static std::string var (int i);
static unsigned long total();
protected:
Expand Down
32 changes: 19 additions & 13 deletions pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
using namespace tag;
using fileexp::mass_tag;
using std::string;
using std::wstring;
using charset::conv;

// "inside out" way of specifying what you want.
// - kind of lazy. but hey long live code reuse :)
Expand All @@ -25,28 +27,32 @@ using std::string;
namespace {
static char error[] = "illegal variable: %_";

struct counter {
struct counter : stredit::format {
handler* tag; // Borland doesn't like ref's in aggr's?
char var[3];
unsigned w;
mutable unsigned w;
mutable ptr mod;

const char* operator()(char);
counter(handler* h) : tag(h), w(0) { }
virtual result var (ptr& p, ptr end) const;
virtual result code (ptr& p, ptr end) const
{ mod = p; return stredit::format::code(p, end); }
};

const char* counter::operator()(char c)
counter::result counter::var(ptr& p, ptr) const
{
if(var[1]++ == '9') // limit reached
if(++w == 10) // limit reached
throw std::out_of_range("too many variables in pattern");
ID3field field = mass_tag::field(c);
ID3field field = mass_tag::field(*p);
if(field < tag::FIELD_MAX) {
++w, tag->set(field, var);
} else if(c == 'x') {
const string& pre = conv<wchar_t>(wstring(mod,p)).str<char>();
tag->set(field, pre + char('0'+w));
} else if(*p == 'x') {
; // pass over in silence
} else {
error[sizeof error-2] = c;
error[sizeof error-2] = *p;
throw std::out_of_range(error);
}
return "*";
return ++p, "*";
}
}

Expand All @@ -56,8 +62,8 @@ pattern::pattern(handler& tag, std::string mask)
while((pos = mask.find('*',pos)) != string::npos) {
mask.replace(pos, 1, "%x");
}
counter var = { &tag, "%0" };
this->assign( stredit::wrap(var)(mask) );
counter var(&tag);
this->assign( var(mask) );
num = var.w;
}

23 changes: 21 additions & 2 deletions sedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extern void deprecated(const char*);

namespace stredit {

enum style { as_is, name, lowr, camel };
enum style { as_is, name, lowr, split };

struct filtered_char { // filter low-ascii
bool operator()(wchar_t c)
Expand Down Expand Up @@ -76,6 +76,22 @@ void capitalize(wstring& s)
}
}

// padcamels("ReformatAStringLikeThis") -> "Reformat A String Like This"

void padcamels(wstring& s)
{
wstring::const_iterator p;
bool word = false;
wstring r;
for(p = s.begin(); p != s.end(); r.push_back(*p++)) {
if(is_(upper, *p) && word)
r.push_back(' ');
word = !is_(space, *p);
}
s.swap(r);
}


// padnumeric("(300/4)=75", 4) -> "0300/0004=0075"

void padnumeric(wstring& s, unsigned pad)
Expand Down Expand Up @@ -143,6 +159,7 @@ function::result format::code(ptr& p, ptr end) const
case '_': raw = true; continue;
case '+': caps = name; continue;
case '-': caps = lowr; continue;
case '*': caps = split; continue;
case '#': ++num_pad; continue;
case prefix:
return conv<wchar_t>(1, prefix);
Expand Down Expand Up @@ -175,8 +192,10 @@ function::result format::code(ptr& p, ptr end) const
replace_if(s.begin(), s.end(), filtered_char(), ' ');
compress(s);
}
if(caps == split)
padcamels(s);
if(caps == name)
capitalize(s); else
capitalize(s);
if(caps == lowr)
transform(s.begin(), s.end(), s.begin(), char_to_lower());
padnumeric(s, num_pad);
Expand Down
3 changes: 2 additions & 1 deletion sedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ namespace stredit {
};

class format : public function {
static char const prefix = '%';
public:
static char const prefix = '%';

virtual result operator()(const charset::conv<char>& s) const
{ return edit(charset::conv<wchar_t>(s), false); }
protected:
Expand Down

0 comments on commit fd58779

Please sign in to comment.