winamp/Src/Wasabi/Lib/exd.mi

118 lines
3.3 KiB
Mason
Raw Normal View History

2024-09-24 12:54:57 +00:00
//----------------------------------------------------------------------------------------------------------------
// exd.mi
//
// extra definitions for internal objects
//----------------------------------------------------------------------------------------------------------------
#ifndef included
#error This script can only be compiled as a #include
#endif
#ifndef __EXD_MI
#define __EXD_MI
//*****************************************************************************
// String CLASS
//*****************************************************************************
Function String replaceString(string baseString, string toreplace, string replacedby);
/**
replaceString()
Returns the class name for the object.
@param baseString The String which you want to modify.
@param toreplace The String you want to be replaced.
@param replacedby The String instead of 'toreplace'.
@ret The replaced string.
*/
String replaceString(string baseString, string toreplace, string replacedby) {
if (toreplace == "") return baseString;
string sf1 = strupper(baseString);
string sf2 = strupper(toreplace);
int i = strsearch(sf1, sf2);
if (i == -1) return baseString;
string left = "", right = "";
if (i != 0) left = strleft(baseString, i);
if (strlen(basestring) - i - strlen(toreplace) != 0) {
right = strright(basestring, strlen(basestring) - i - strlen(toreplace));
}
return left + replacedby + right;
}
Function String cutString(string baseString, string toreplace);
/**
cutString()
Returns the class name for the object.
@param baseString The String which you want to modify.
@param toreplace The String you want to be replaced.
@ret The replaced string.
*/
String cutString(string baseString, string toreplace) {
if (toreplace == "") return baseString;
int i = strsearch(baseString, toreplace);
if (i == -1) return baseString;
string left = "", right = "";
if (i != 0) left = strleft(baseString, i);
if (strlen(basestring) - i - strlen(toreplace) != 0) {
right = strright(basestring, strlen(basestring) - i - strlen(toreplace));
}
return left + right;
}
Function String fillStringBefore(string baseString, string after, string before);
/**
fillStringBefore()
Returns the class name for the object.
@param baseString The String which you want to modify.
@param toreplace The String you want to be replaced.
@ret The replaced string.
*/
String fillStringBefore(string baseString, string filled, string anchor) {
int i = strsearch(baseString, anchor);
if (i == -1) return baseString;
string left = "", right = "";
if (i != 0) left = strleft(baseString, i);
if (strlen(basestring) - i - strlen(toreplace) != 0) {
right = strright(basestring, strlen(basestring) - i);
}
/* bef.setText(integerToString(i) + " - " + left);
aft.setText(integerToString(strlen(basestring) - i) + " - " + right);
*/ return left + filled + right;
}
Function Int countSubString(string str, string substr);
int countSubString(string str, string substr) {
int n = 0;
for ( int i = 0; i < 666; i++ ) {
int r = strSearch(str, substr);
#ifdef DEBUG
debug(integerToString(r));
#endif
if (r == -1) i = 666;
else {
str = strright(str, strlen(str) - (r + 1));
n++;
if (strlen(str) - r == 1) return n;
}
}
return n;
}
#endif