Skip to content

Commit 1a41341

Browse files
committed
Str additioinal functions
1 parent 05fb89d commit 1a41341

File tree

3 files changed

+197
-87
lines changed

3 files changed

+197
-87
lines changed

src/AudioBasic/Str.h

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,16 @@ class Str {
619619
return result;
620620
}
621621

622+
/// Converts the string to a double
623+
double toDouble() {
624+
double result = 0;
625+
char *eptr;
626+
if (!isEmpty()){
627+
result = strtod(chars, &eptr);
628+
}
629+
return result;
630+
}
631+
622632
/// Converts the string to lowercase letters
623633
void toLowerCase(){
624634
if (chars!=nullptr){
@@ -654,6 +664,85 @@ class Str {
654664
return result;
655665
}
656666

667+
bool containsNumber() {
668+
for (int j=0;j<len;j++){
669+
if (isdigit(chars[j])){
670+
return true;
671+
}
672+
}
673+
return false;
674+
}
675+
676+
/// Returns true if the string is an integer
677+
bool isInteger() {
678+
bool result = containsNumber();
679+
int dot_count = 0;
680+
int minus_count = 0;
681+
for (int j=0;j<len;j++){
682+
char c = chars[j];
683+
if(!isdigit(c)){
684+
switch(c){
685+
case '-':
686+
minus_count++;
687+
if (minus_count>1){
688+
result = false;
689+
}
690+
break;
691+
default:
692+
result = false;
693+
break;
694+
}
695+
}
696+
}
697+
return result;
698+
}
699+
700+
/// Determines the number of decimals in the number string
701+
int numberOfDecimals() {
702+
int result = 0;
703+
int pos = indexOf(".");
704+
if (pos>=0){
705+
for (int j=pos+1;j<len;j++){
706+
if (isdigit(chars[j])){
707+
pos++;
708+
} else {
709+
break;
710+
}
711+
}
712+
}
713+
return result;
714+
}
715+
716+
// Returns true if the string is a number
717+
bool isNumber() {
718+
bool result = containsNumber();
719+
int dot_count = 0;
720+
int minus_count = 0;
721+
for (int j=0;j<len;j++){
722+
char c = chars[j];
723+
if(!isdigit(c)){
724+
switch(c){
725+
case '-':
726+
minus_count++;
727+
if (minus_count>1){
728+
result = false;
729+
}
730+
break;
731+
case '.':
732+
dot_count++;
733+
if (dot_count>1){
734+
result = false;
735+
}
736+
break;
737+
default:
738+
result = false;
739+
break;
740+
}
741+
}
742+
}
743+
return result;
744+
}
745+
657746
protected:
658747
char* chars = nullptr;
659748
bool is_const=false;

src/AudioLibs/AudioKit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ class AudioKitStream : public AudioStreamX {
244244
/// Update the audio info with new values: e.g. new sample_rate,
245245
/// bits_per_samples or channels
246246
virtual void setAudioInfo(AudioBaseInfo info) {
247+
LOGI(LOG_METHOD);
247248
cfg.sample_rate = info.sample_rate;
248249
cfg.bits_per_sample = info.bits_per_sample;
249250
cfg.channels = info.channels;

0 commit comments

Comments
 (0)