예제 #1
0
void CStringEx::TestExp()
{
 int pos;
 pos = max(ReverseFind('-'),ReverseFind('+'));
 if(pos<2) return;
 if(this[pos-1]==32) return;
 if(this[pos-1]==69 || this[pos-1]==101) return;
 Insert(pos-1,'E');
}
예제 #2
0
int CMyString::FindNameIndex() const
{
    int ind1 = ReverseFind('/');
    int ind2 = ReverseFind('\\');
    int index;
    if (ind1>=0 && ind2>=0) index = ind1 > ind2 ? ind1 : ind2;
    else if (ind1>=0)       index = ind1;
    else if (ind2>=0)       index = ind2;
    else return 0;
    return index + 1;
}
// return : "txt"
CString CFileString::GetFileExt()
{
	int iLen = GetLength(), iLoc = ReverseFind('.');
	if (iLoc == -1) return "";

	return Right(iLen - iLoc - 1);
}
예제 #4
0
CString CMyString::GetExceptExt() const
{
    if (IsEmpty()) return _T("");
    int index = ReverseFind('.');
    if (index < 0) return *this;
    else           return Left(index);
}
예제 #5
0
CString CMyString::GetExt() const
{
    if (IsEmpty()) return _T("");
    int index = ReverseFind('.');
    if (index < 0) return _T("");
    else           return Mid(index);
}
// this   : "c:\\temp\\1.txt"
// return : "c:\\temp"
CString CFileString::GetDirName()
{
	int iLoc = ReverseFind('\\');
	if (iLoc == -1) return "";

	return Left(iLoc);
}
예제 #7
0
int CUnicodeString::ReverseFind(CHAR ch) const
{
	CHAR c[] = "\0\0";
	c[0] = ch;
	WCHAR wc[] = L"\0\0";;
	MultiByteToWideChar(CP_ACP, 0, c, 1, wc, 1);
	return ReverseFind(wc[0]);
}
예제 #8
0
//--------------------------------------------------------------------------------
CString CPathString::GetExtension()
{
    int nIndex = ReverseFind('.');
    CString sTemp;

    if(nIndex != -1)
        sTemp = Mid(nIndex);

    return sTemp;
}
예제 #9
0
HeapString HeapString::AfterLast(char ch) const
{
	HeapString str;
	int pos = ReverseFind(ch);
	if (pos == -1)
		str = *this;
	else
		str = m_string + pos + 1;

	return str;
}
예제 #10
0
HeapString HeapString::BeforeLast(char ch) const
{
	HeapString str;
	int pos = ReverseFind(ch);
	if (pos == -1)
		str = *this;
	else
		str = HeapString(m_string, pos);

	return str;
}
예제 #11
0
파일: FILENAME.CPP 프로젝트: CUBRID/cubrid
CString CFilename::GetLeaf()
{
CString	tempstr;
int	pos;

	if ((pos = ReverseFind('\\')) != -1) {
		tempstr = Mid(pos + 1);
	} else {
		tempstr.Empty();
	}

	return tempstr;
}
예제 #12
0
int	CCOMStringW::ReverseFind(WCHAR ch) const
{
	return ReverseFind(ch, 0);
}
예제 #13
0
파일: VobFile.cpp 프로젝트: hiplayer/mpc_hc
                REFERENCE_TIME rtCurrentTime = 10000i64 * (((hours * 60 + minutes) * 60 + seconds) * 1000 + mmseconds);
                rtTotalTime += rtCurrentTime;
            }
        }
        rtDuration += rtTotalTime;
        m_pChapters[currentProgram + 1] = rtDuration;
    }

    m_ifoFile.Close();

    int offset = -1;

    vobs.RemoveAll();

    fn = fn.Left(fn.ReverseFind('.') + 1);
    fn.TrimRight(_T(".0123456789"));
    for (int i = 0; i < 100; i++) {
        CString vob;
        vob.Format(_T("%s%d.vob"), fn, i);

        CFileStatus status;
        if (!CFile::GetStatus(vob, status)) {
            if (i == 0) {
                continue;
            } else {
                break;
            }
        }

        if (status.m_size & 0x7ff) {
예제 #14
0
int ON_wString::ReverseFind( unsigned char c ) const
{
  wchar_t w = c2w((char)c);
  return ReverseFind( w );
}
예제 #15
0
int AString<B>::ReverseFind(const tchar *s, int from) const
{
	return ReverseFind(strlen__(s), s, from);
}
예제 #16
0
int AString<B>::ReverseFind(int chr) const
{
	return B::GetCount() ? ReverseFind(chr, B::GetCount() - 1) : -1;
}
예제 #17
0
파일: AString.hpp 프로젝트: koz4k/soccer
int AString<B>::ReverseFindAfter(int len, const tchar *s, int from) const
{
	int q = ReverseFind(len, s, from);
	return q >= 0 ? q + len : -1;
}
예제 #18
0
int ON_wString::ReverseFind( char c ) const
{
  wchar_t w = c2w(c);
  return ReverseFind( w );
}
int ON_String::ReverseFind( unsigned char c ) const
{
  return ReverseFind( (char)c );
}
예제 #20
0
/****************************************************************************
PARAMETERS:
text        - HTML to process for if/else blocks

RETURNS:
The string containing the processed HTML

REMARKS:
This function replaces #if, #else, #elif, and #endif directives with the text
contained within the blocks, dependant on the value of the given boolean
variable. The variable is created by making a sub class of wxIfElseVariable.
Dynamic class construction is used at run time internally to create an instance
of this class and access the value of the variable.

SEE ALSO:
wxIfElseVariable
****************************************************************************/
wxString wxIfElsePrep::Process(
    const wxString& text) const
{
	int b;
	char ft[] = "<!--#if ";
	char ftend[] = "<!--#endif-->";
    char ftelse[] = "<!--#else-->";
    char ftnot[] = "<!--#if not ";
    char ftnot2[] = "<!--#if !";
    char ftelif[] = "<!--#elif ";
	
    // make a copy so we can replace text as we go without affecting the original
	wxString output = text;

    // Avoid duplication of our parsing code by turning any #elif blocks into appropriate
    // else/if blocks
    while ((b = ReverseFind(output.Lower(), ftelif)) != -1) {
        int e;
        // Replace beginning of block
        e = output.find("-->", b + strlen(ftelif));

        if (e == wxString::npos) {
#ifdef CHECKED		
            wxMessageBox("wxHTML #elif error: Premature end of file while parsing #elif.","Error",wxICON_ERROR);
#endif
            break;
            }

        // Convert to lower case so find is easy, grab everything after #elif tag
        wxString remains = (output.Mid(e+strlen("-->"))).Lower();

        // find matching else or endif
        int nextif, nextendif;
        int ifcount = 1, min = 0;
        do {
            nextif = remains.find(ft, min);
            nextendif = remains.find(ftend, min);
            if (nextif < nextendif && nextif != wxString::npos) {
                ifcount++;
                min = nextif+1;
                }
            else {
                ifcount--;
                min = nextendif+1;
                }

            if (nextendif == wxString::npos) {
#ifdef CHECKED		
                wxMessageBox("wxHTML #elif error: Premature end of file before finding #endif.","Error",wxICON_ERROR);
#endif
                break;
                }
            // once ifcount reaches 0 again we have found our matchin #endif
            } while (ifcount > 0);

        // If it couldn't be found die gracefully
        if (nextendif == wxString::npos) {
            // We already displayed a message, just break all the way out
            break;
            }

        int elifsize = e - (b + strlen(ftelif)) + strlen("-->");
        // Create the #if/else block, removing the #elif code
        output = output.Mid(0, b) +
            wxString(wxString(ftelse)+wxString(ft)) +
            output.Mid(b+strlen(ftelif), elifsize+nextendif) +
            wxString(ftend) +
            output.Mid(b+strlen(ftelif)+elifsize+nextendif);
        }
	
    // Parse out the if else blocks themselves
    while ((b = ReverseFind(output.Lower(), ft)) != -1) {
		// Loop until every #if directive is found
		// We search from the end of the string so that #if statements will properly recurse
		// and we avoid the hassle of matching statements with the correct <!--#endif-->
        bool notval = false;
        int off = 0;
        int end;
        wxString usecode, code;
        wxString cname;
        wxString tag;
        bool value;

        code = wxString("");

        // grab the tag and get the name of the variable
        end = (output.Mid(b)).Find("-->");
        if (end == -1) {
#ifdef CHECKED		
            wxMessageBox("wxHTML #if error: Premature end of file while parsing #if.","Error",wxICON_ERROR);
#endif
            break;
			}

        end += 3;
        // remove the <!--#if and --> sections from the tag before passing it on to be parsed
        tag = output.Mid(b+strlen(ft), end-strlen(ft)-3);
        output.Remove(b, end);

        value = ParseIfStatementValue(tag);

        // Find the end of the tag (<!--#endif-->) and copy it all into the variable code
        end = ((output.Mid(b)).Lower()).Find(ftend);
        if (end == -1) {
#ifdef CHECKED		
            wxMessageBox("wxHTML #if error: Premature end of file while searching for matching #endif.","Error",wxICON_ERROR);
#endif
            break;
			}

        code = output.Mid(b, end);
        output.Remove(b, end+strlen(ftend)); // remove the entire #if block from original document

        // Find out if there is an else statement
        end = (code.Lower()).Find(ftelse);
        if (end != -1) {
            if (!value) {
                // Use the else statement
                usecode = code.Mid(end+strlen(ftelse));
                }
            else {
                // Use statement before #else
                usecode = code.Mid(0, end);
                }
            }
        else if (value) {
            // There is no #else statement
            usecode = code;
            }

        if (usecode != wxString(""))
            output = (output.Mid(0,b) + usecode + output.Mid(b));
		}

    return output;
}
예제 #21
0
/****************************************************************************
PARAMETERS:
str        - text of #if statement

RETURNS:
true or false depending on how it evaluated

REMARKS:
TODO: rewrite this whole thing using regular expressions when they are done.

SEE ALSO:
wxIfElseVariable
****************************************************************************/
bool ParseIfStatementValue(
    wxString &str)
{
    // Find out if the tag has parenthesis
    // recursive to parse the text within the parenthesis,
    // replacing the text with 1 or 0, (hardcoded true or false)
    int b;
    while ((b = str.Find('(')) != -1) {
        int e;
        // Find the matching parenthesis
        int nextbeg, nextend;
        int parencount = 1, min = b+1;
        do {
            nextbeg = str.find('(', min);
            nextend = str.find(')', min);
            if (nextbeg < nextend && nextbeg != wxString::npos) {
                parencount++;
                min = nextbeg+1;
                }
            else {
                parencount--;
                min = nextend+1;
                }

            if (nextend == wxString::npos) {
#ifdef CHECKED		
                wxMessageBox("wxHTML #if\\else error: Unmatched parenthesis in #if expression.","Error",wxICON_ERROR);
#endif
                return true;
                }
            // once parencount reaches 0 again we have found our matchin )
            } while (parencount > 0);

        e = nextend;

        // Extract the expression from the parenthesis block and recurse
        // to solve it.
        wxString tag;
        tag = str.Mid(b+1, e-b-1);
        bool val = ParseIfStatementValue(tag);
        // Add extra spaces just in case of NOT(VAL)
        if (val) str = str.Mid(0, b) + " 1" + str.Mid(e+1);
        else str = str.Mid(0, b) + " 0" + str.Mid(e+1);
        }

    // Remove spaces from left and right
    str.Trim(false);
    str.Trim(true);

    // Convert text method of operators "AND" and "OR" to c style
    // this makes only one special case necessary for each later on
    str.Replace(" AND ", "&&");
    str.Replace(" OR ", "||");
    str.Replace(" EQUALS ", "==");

    // Check for equals statements
    // == statements are special because they are evaluated as a single block
    int equ;
    equ = str.find("==");
    while (equ != wxString::npos) {
        int begin, end;
        int begin2, end2; // ends of words
        begin = equ-1;
        end = equ+2;

        // remove spaces, find extents
        while (end < str.Length() && str.GetChar(end) == ' ')
            end++;
        while (begin >= 0 && str.GetChar(begin) == ' ')
            begin--;
        end2 = end;
        begin2 = begin;
        if (str.GetChar(end2) == '\'' || str.GetChar(end2) == '\"') {
            end2++;
            while (end2 < str.Length() && str.GetChar(end2) != '\'' && str.GetChar(end2) != '\"' )
                end2++;
            end2++;
            }
        else {
            while (end2 < str.Length() && IsLetter(str.GetChar(end2)))
                end2++;
            }
        while (begin >= 0 && IsLetter(str.GetChar(begin)))
            begin--;

        if (begin < 0) begin = 0;
        else begin++;
        if (end2 >= str.Length()) end2 = str.Length();

        wxString tmpeq = GetEquals(str.Mid(begin, begin2-begin+1), str.Mid(end, end2-end));
        str = str.Mid(0, begin) + wxString(" ") + tmpeq + wxString(" ") +
            str.Mid(end2);
        equ = str.find("==");

        // Remove spaces from left and right
        str.Trim(false);
        str.Trim(true);
        }

    // We use ReverseFind so that the whole left expression gets evaluated agains
    // the right single item, creating a left -> right evaluation
    // Search for || operators, recurse to solve (so we don't have to handle special cases here)
    int and, or;
    and = ReverseFind(str, "&&");
    or = ReverseFind(str, "||");
    if ( (and != -1) || (or != -1) ) {
        wxString tag1, tag2;
        // handle the rightmost first to force left->right evaluation
        if ( (and > or) ) {
            return (
                ParseIfStatementValue(tag2 = str.Mid(and+2)) &&
                ParseIfStatementValue(tag1 = str.Mid(0, and)) );
            }
        else {
            return (
                ParseIfStatementValue(tag2 = str.Mid(or+2)) ||
                ParseIfStatementValue(tag1 = str.Mid(0, or)) );
            }
        }

    // By the time we get to this place in the function we are guarenteed to have a single
    // variable operation, perhaps with a NOT or ! operator
    bool notval = false;

    // search for a NOT or ! operator
    if (str.Mid(0, 1) == "!") {
        str.Remove(0, 1);
        str.Trim(false); // trim spaces from left
        notval = true;
        }
    else if (str.Mid(0,4).CmpNoCase("NOT ") == 0) {
        str.Remove(0, 4);
        str.Trim(false); // trim any extra spaces from left
        notval = true;
        }

    // now all we have left is the name of the class or a hardcoded 0 or 1
    if (str == "") {
#ifdef CHECKED		
        wxMessageBox("wxHTML #if\\else error: Empty expression in #if\\#elif statement.","Error",wxICON_ERROR);
#endif
        return true;
        }

    // check for hardcoded 0 and 1 cases, (these are used by parenthesis catcher)
    // this just decomplicates the recursion algorithm
    if (str == "0") return notval;
    if (str == "1") return !notval;

    // Grab the value from the variable class identified by cname
    bool value = wxIfElseVariable::GetValue(str);
    if (notval) value = !value;
    return value;

}