コード例 #1
0
/* Returns the name of the end point.
*  Input: String location
*  Output: Very ending of string after last "/"
 */
CharString FileSystem::getNameFromString(CharString location) {
    // gets the name of the last "/dir/dir2/name", even if it ends with "/".
    if(location.get()[location.getSize()-1] == '/') {
        // remove trailing "/".
        location.get()[location.getSize()-1] = '\0';
        location.setSize(location.getSize()-1);
    }

    CharString result = CharString("");
    // split all by "/".
    if(location.contains("/")) {
        // get the very last result of the split.
        LinkedList<CharString>* sresult = location.split('/','`');
        result = *sresult->get(sresult->size()-1);
    } else {
        result = location;
    }

    return result;
}
コード例 #2
0
/*
 * Desc: Takes in a single line and expresses the line in a math formula to solve it.
 * Input: CharString* Line.
 * Output: (Console) Output of all expressions.
 * */
CharString Eval(CharString Line) {
    //cout << line << endl;
    // get length of line
    int lsize = 0;
    for(int i=0; i<Line.getSize(); i++) {
        if(Line.get()[i] != 0x0) {
            lsize++;
        }
    }
    Line.setSize(lsize);


    // PARSE each section. Format SHOULD be like this:
    // 1 + 2 [number operator number]
    // 1 + 2 * 3 [n o n o n]
    // 1 + 5 * 10^2 [n o n o non]
    // 110/ 98 [no n] (Automatic parse finding)

    // list of operators:
    // () + - / * ^ % < > = <= >= [NOTE that as of this time, parentheses will not be used]

    // Thus, it can be infered that we can break up each system by placing the most important
    //  System (order of operations) on the top of the stack and placing the least important
    // +/- at the bottom of the stack...

    // Order of operations:
    //  ^  /  *  +  -  (>= = <= < > [END-CLASS operators])

    // Parse method:
    //  1.) loop-through n times to get full stack.

    NumStack = new Stack(); // NumStack is used to store the initial numbers
    OpStack = new Stack(); // OpStack is used to store the initial operators

    // note that both stacks store information through the same MathOperationNode Type.
    //  This will be solved later when we interlace the operators with the variables.
    char* LineD = Line.get();
    char* NumTemp = new char();
    int NumTempLen = 0;
    MOperator OpTemp = none;
    for(int i=0; i<Line.getSize(); i++) {
        char g = LineD[i];
        MOperator tOp = getOperatorFromChar(g);

        if(isCharNumber(g)) { // is this a number?
            // this is a single digit for NumTemp. Add to it.
            NumTemp[NumTempLen] = g;
            NumTempLen++;

            // dump OpTemp if it is available.
            dumpOp(OpTemp);
            OpTemp = none;
        } else if (tOp != none) {
            if(OpTemp != none) {
                MOperator gox = combineOperators(tOp,OpTemp);
                if(gox != none) OpTemp = gox;
            } else {
                OpTemp = tOp;
            }

            // dump NumTemp if it is available.
            dumpNum(NumTemp,NumTempLen);
            NumTempLen=0;
        } else {
            // dump NumTemp if it is available.
            // dump OpTemp if it is available.
            dumpNum(NumTemp,NumTempLen);
            NumTempLen=0;
            dumpOp(OpTemp);
            OpTemp = none;
        }
    }

    // dump NumTemp if it is available.
    // dump OpTemp if it is available.
    dumpNum(NumTemp,NumTempLen);
    NumTempLen=0;
    dumpOp(OpTemp);
    OpTemp = none;

    while(OpStack->size > 0) {
        int res = doOp();
        //cout << "=" << res << endl;
        NumStack->push(res);
    }
    int c = NumStack->pop();
    if(c == -98) cout << "F";
    else if(c == -99) cout << "T";
    else cout << c;

    return CharString::ConvertFromInt(c);
}