libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
numname.h
Go to the documentation of this file.
1
8#pragma once
9
11#include <promeki/core/string.h>
12
14
23class NumName {
24 public:
31 static NumName parse(const String &str, int *val = nullptr);
32
34 NumName() = default;
35
43 NumName(const String &prefix, const String &suffix, int digits, bool padded) :
44 px(prefix), sx(suffix), dl(digits), pad(padded) {}
45
50 NumName(const String &str) { *this = parse(str); }
51
56 bool isValid() const { return dl > 0; }
57
63 String name(int val) const {
64 return px + String::number(val, 10, pad ? dl : 0, '0') + sx;
65 }
66
71 String prefix() const { return px; }
72
77 String suffix() const { return sx; }
78
83 bool isPadded() const { return pad; }
84
89 int digits() const { return dl; }
90
99 String filemask() const {
100 String mask;
101 if(pad) {
102 mask = "%0";
103 mask += String::number(dl);
104 mask += 'd';
105 } else {
106 mask = "%d";
107 }
108 return px + mask + sx;
109 }
110
119 String hashmask() const {
120 return px + String(pad ? dl : 1, '#') + sx;
121 }
122
124 bool operator==(const NumName &other) const {
125 return dl == other.dl &&
126 pad == other.pad &&
127 px == other.px &&
128 sx == other.sx;
129 }
130
132 bool operator!=(const NumName &other) const {
133 return !(*this == other);
134 }
135
145 bool isInSequence(const NumName &n) const {
146 if(!n.isValid() || n.px != px || n.sx != sx) return false;
147 if(n.pad && !pad && n.dl > dl) return false;
148 if(!n.pad && pad && dl > n.dl) return false;
149 if(n.pad && pad && n.dl != dl) return false;
150 return true;
151 }
152
153 private:
154 String px; // Prefix
155 String sx; // Suffix
156 int dl = 0; // Digit length
157 bool pad = false; // Padding
158
159};
160
162
Dynamic array container wrapping std::vector.
Definition list.h:40
Deconstructs a numbered name into its prefix, number, and suffix components.
Definition numname.h:23
static NumName parse(const String &str, int *val=nullptr)
Parses a string into a NumName.
bool operator!=(const NumName &other) const
Returns true if the NumNames differ in any component.
Definition numname.h:132
String hashmask() const
Returns a hash-style mask for the numbered name.
Definition numname.h:119
String suffix() const
Returns the suffix portion of the name (text after the number).
Definition numname.h:77
bool isInSequence(const NumName &n) const
Checks whether another NumName belongs to the same sequence.
Definition numname.h:145
String prefix() const
Returns the prefix portion of the name (text before the number).
Definition numname.h:71
bool isPadded() const
Checks whether the numeric field is zero-padded.
Definition numname.h:83
String name(int val) const
Generates a full name string with the given numeric value.
Definition numname.h:63
NumName()=default
Constructs an invalid (empty) NumName.
bool operator==(const NumName &other) const
Returns true if both NumNames have identical components.
Definition numname.h:124
bool isValid() const
Checks whether this NumName contains a valid numeric field.
Definition numname.h:56
NumName(const String &str)
Constructs a NumName by parsing a string.
Definition numname.h:50
String filemask() const
Returns a C-style printf format mask for the numbered name.
Definition numname.h:99
NumName(const String &prefix, const String &suffix, int digits, bool padded)
Constructs a NumName from explicit components.
Definition numname.h:43
int digits() const
Returns the number of digits in the numeric field.
Definition numname.h:89
Encoding-aware string class with copy-on-write semantics.
Definition string.h:35
static String number(int8_t value, int base=10, int padding=0, char padchar=' ', bool addPrefix=false)
Converts a numeric value to its String representation.
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19