⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 staf.cpp

📁 Software Testing Automation Framework (STAF)的开发代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    return rc;}STAFRC_t STAFFree(STAFHandle_t handle, char *result){    return RealSTAFFree(handle, result);}STAFRC_t RealSTAFFree(STAFHandle_t, char *result){    STAFRC_t rc = kSTAFUnknownError;    try    {        delete [] result;        rc = kSTAFOk;    }    catch (...)    {        rc = kSTAFUnknownError;    }    return rc;}void createCResult(STAFString result, char **resultPtr,                   unsigned int *resultLength){    *resultPtr = 0;    *resultLength = 0;    try    {        // We use a temporary to hold the result so that it will not        // be set if we throw an exception allocating memory        STAFStringBufferPtr theResult = result.toCurrentCodePage();        unsigned int theResultLength = theResult->length();        if (theResultLength != 0)        {            *resultPtr = new char[theResultLength + 1];            memcpy(*resultPtr, theResult->buffer(), theResultLength);            (*resultPtr)[theResultLength] = 0;            *resultLength = theResultLength;        }    }    catch (...)    {    }}STAFRC_t STAFAddPrivacyDelimiters(STAFStringConst_t inData,                                  STAFString_t *result){    if (inData == 0) return kSTAFInvalidObject;    STAFRC_t rc = kSTAFOk;        try    {        STAFString data(inData);        if (data.length() == 0)        {            *result = data.adoptImpl();            return rc;        }        // Check if data already has privacy delimiters at beginning and end        if (data.find(sOpenPD) == 0)        {            int index = data.length() - sClosePD.length();            if (index >= sOpenPD.length())            {                if ((data.subString(index) == sClosePD) &&                    (data.subString(index - 1) != sEscClosePD))                {                    // Don't add additional privacy delimiters.                    *result = data.adoptImpl();                    return rc;                }            }        }        // 1) Add an opening privacy delimiter, !!@, to the beginning of the        //    data.        //        // 2) Escape all occurrences of the opening and closing privacy        //    delimiters.  That is, replace all occurrences of !!@ with        //    ^!!@ and replace all occurrences of @!! with ^@!!.        //        //    Note:  Escape the closing privacy delimiters before escaping the        //    opening privacy delimiters to avoid a problem if the data        //    includes back to back closing privacy delimiters, ^@!!@!!, which        //    could be mistaken for an opening privacy delimiter, !!@, if the        //    closing privacy delimiters were not escaped first.        //        // 3) Add a closing privacy delimiter, @!!, to the end of the data.        data = STAFString(sOpenPD +                          (data.replace(sClosePD, sEscClosePD)).                           replace(sOpenPD, sEscOpenPD) +                          sClosePD);                *result = data.adoptImpl();    }    catch (...)    {        rc = kSTAFUnknownError;    }    return rc;}STAFRC_t STAFRemovePrivacyDelimiters(STAFStringConst_t data,                                     unsigned int numLevels,                                     STAFString_t *outString){    if (data == 0) return kSTAFInvalidObject;    STAFRC_t rc = kSTAFOk;        try    {        STAFString result(data);                if ((result.length() == 0) ||            (result.find(sOpenPD) == STAFString::kNPos))        {            *outString = result.adoptImpl();            return rc;        }        unsigned int index = 0;        unsigned int nextIndex = 0;        unsigned int openIndex = 0;        unsigned int closeIndex = 0;        unsigned int level = 0;                // numLevels = 0 means to remove all privacy masks.        // numLevels = 1+ means to remove up to the specified number of levels        //             of privacy data.        bool noMoreLevels = false;        if (numLevels == 0)            noMoreLevels = true;        // Remove privacy delimiters for the specified number of levels        for (; ((numLevels == 0) || (level < numLevels)); ++level)        {            // Check if any more unescaped opening privacy delimiters.            nextIndex = 0;                        openIndex = findNextUnescapedOpeningPD(result, nextIndex);            // If no more unescaped opening privacy delimiters, break out of            // the loop since no more levels of private data            if (openIndex == STAFString::kNPos)            {                noMoreLevels = true;                break;            }            // Check if any more unescaped closing privacy delimiters after            // the position of the opening unescaped privacy delimiter.                        nextIndex = openIndex + sOpenPD.length();                        closeIndex = findNextUnescapedClosingPD(result, nextIndex);            // If no more unescaped closing privacy delimiters, break out of            // the loop since no more levels of private data            if (closeIndex == STAFString::kNPos)            {                noMoreLevels = true;                break;            }            // Handle all opening and closing privacy delimiters at this level            while (true)            {                // If there are any escaped privacy delimiters between this                // opening privacy delimiter and the closing privacy delimiter,                // remove the escape character (^) from them.                unsigned int nextOpenIndex = result.find(                   sEscOpenPD, openIndex + sOpenPD.length());                for (; ((nextOpenIndex != STAFString::kNPos) &&                        (nextOpenIndex < closeIndex));)                {                    result = result.subString(0, nextOpenIndex) +                             result.subString(nextOpenIndex + 1);                    closeIndex--;                    nextOpenIndex = result.find(                        sEscOpenPD, nextOpenIndex + sOpenPD.length());                }                unsigned int nextCloseIndex = result.find(                    sEscClosePD, openIndex + sOpenPD.length());                for (; ((nextCloseIndex != STAFString::kNPos) &&                        (nextCloseIndex < closeIndex));)                {                    result = result.subString(0, nextCloseIndex) +                        result.subString(nextCloseIndex + 1);                    closeIndex--;                    nextCloseIndex = result.find(                        sEscClosePD, nextCloseIndex + sClosePD.length());                }                // Remove these opening and closing privacy delimiters                unsigned int beginPos = openIndex + sOpenPD.length();                if (openIndex == 0)                {                    result = result.subString(beginPos, closeIndex - beginPos) +                             result.subString(closeIndex + sClosePD.length());                }                else                {                    result = result.subString(0, openIndex) +                             result.subString(beginPos, closeIndex - beginPos) +                             result.subString(closeIndex + sClosePD.length());                }                                // Check if any more unescaped opening privacy delimiters after                // this closing delimiter.                nextIndex = closeIndex;                openIndex = findNextUnescapedOpeningPD(result, nextIndex);                if (openIndex == STAFString::kNPos)                {                    break;                }                // Check if any more unescaped closing privacy delimiters after                // the position of the opening unescaped privacy delimiter.                nextIndex = openIndex + sOpenPD.length();                closeIndex = findNextUnescapedClosingPD(result, nextIndex);                if (closeIndex == STAFString::kNPos)                {                    break;                }            }        }        // Check if there are any more levels of privacy delimiters        if (!noMoreLevels)        {            // Check if any more unescaped opening privacy delimiters.            nextIndex = 0;            openIndex = findNextUnescapedOpeningPD(result, nextIndex);            if (openIndex == STAFString::kNPos)            {                noMoreLevels = true;            }            else            {                // Check if any more unescaped closing privacy delimiters after                // the position of the opening unescaped privacy delimiter.                nextIndex = openIndex + sOpenPD.length();                closeIndex = findNextUnescapedClosingPD(result, nextIndex);                if (closeIndex == STAFString::kNPos)                {                    noMoreLevels = true;                }            }        }                if (noMoreLevels)        {            // Replace any escaped closing privacy delimiters, ^@!!, with            // unescaped closing privacy delimiters, @!!.            result = result.replace(sEscClosePD, sClosePD);            // Replace any escaped opening privacy delimiters, ^!!@, with            // unescaped opening privacy delimiters, !!@.            result = result.replace(sEscOpenPD, sOpenPD);        }        *outString = result.adoptImpl();    }    catch (...)    {        rc = kSTAFUnknownError;    }    return rc;}STAFRC_t STAFMaskPrivateData(STAFStringConst_t inData, STAFString_t *result){    if (inData == 0) return kSTAFInvalidObject;    STAFRC_t rc = kSTAFOk;        try    {        STAFString data(inData);                if ((data.length() == 0) ||            (data.find(sOpenPD) == STAFString::kNPos))        {            *result = data.adoptImpl();            return rc;        }        STAFString outString("");        unsigned int index = 0;        unsigned int openIndex = 0;        unsigned int closeIndex = 0;        // Find all unescaped opening privacy delimiters with matching         // unescaped closing privacy delimiters and replace all data between         // these privacy delimiters with asterisks.        while ((openIndex = data.find(sOpenPD, closeIndex)) !=               STAFString::kNPos)        {            if ((openIndex > 0) && (data.sizeOfChar(openIndex - 1) == 1) &&                (data.subString(openIndex - 1, 1) == sCaret))            {                // Found an escaped privacy delimiter                closeIndex = openIndex + sOpenPD.length();                continue;            }            // Find position of first unescaped closing privacy delimiter            // after this unescaped opening delimiter.            closeIndex = data.find(sClosePD, openIndex + sOpenPD.length());            while (closeIndex != STAFString::kNPos)            {                if ((data.sizeOfChar(closeIndex - 1) == 1) &&                    (data.subString(closeIndex - 1, 1) == sCaret))                {                    // Escaped; Find next unescaped closing privacy delimiter                    closeIndex = data.find(                        sClosePD, closeIndex + sClosePD.length());                 }                else                {                    break;  // Found unescaped closing privacy delimiter                }            }            if (closeIndex == STAFString::kNPos)            {                break;  // Exit since no unescaped closing @!! strings left            }            outString += data.subString(index, openIndex - index);            // Replace the privacy delimiters and data with "*"s            unsigned int replaceLength = closeIndex - openIndex +                sClosePD.length();            for (unsigned int i = 1; i <= replaceLength; i++)            {                outString += "*";            }            index = closeIndex + sClosePD.length();            if (index >= data.length()) break;        }        if (index < data.length())        {            outString += data.subString(index);        }        *result = outString.adoptImpl();    }    catch (...)    {        rc = kSTAFUnknownError;    }    return rc;}STAFRC_t STAFEscapePrivacyDelimiters(STAFStringConst_t inData,                                     STAFString_t *result){    if (inData == 0) return kSTAFInvalidObject;    STAFRC_t rc = kSTAFOk;        try    {        STAFString data(inData);                if (data.length() != 0)        {            // Escape all opening or closing delimiters.            data = data.replace(sClosePD, sEscClosePD);            data = data.replace(sOpenPD, sEscOpenPD);        }        *result = data.adoptImpl();    }    catch (...)    {        rc = kSTAFUnknownError;    }    return rc;}// Returns the index of the next unescaped opening privacy delimiter// found at or after the specified index.  If no more unescaped opening// privacy delimiters are found, returns STAFString::kNPos.//// Input://   data  - A string that may contain opening privacy delimiters//   index - The index to begin searching the data for an unescaped//           opening privacy delimiterunsigned int findNextUnescapedOpeningPD(const STAFString &data, unsigned int index){    unsigned int i;        while ((i = data.find(sOpenPD, index)) != STAFString::kNPos)    {        if ((i > 0) && (data.sizeOfChar(i - 1) == 1) &&            (data.subString(i - 1, 1) == sCaret))        {            index = i + sOpenPD.length();        }        else        {            break;        }    }    return i;}// Returns the index of the next unescaped closing privacy delimiter// found at or after the specified index.  If no more unescaped closing// privacy delimiters are found, returns STAFString::kNPos.//// Input://   data  - A string that may contain closing privacy delimiters//   index - The index to begin searching the data for an unescaped//           closing privacy delimiterunsigned int findNextUnescapedClosingPD(const STAFString &data, unsigned int index){    unsigned int i;        while ((i = data.find(sClosePD, index)) != STAFString::kNPos)    {        if ((i > 0) && (data.sizeOfChar(i - 1) == 1) &&            (data.subString(i - 1, 1) == sCaret))        {            index = i + sClosePD.length();        }        else        {            break;        }    }    return i;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -