Ignore:
Timestamp:
Jun 9, 2016, 4:15:48 PM (3 years ago)
Author:
xuedongx
Message:

fix index

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/grep_engine.cpp

    r5045 r5046  
    8282    if ((end_byte < 0xA8) || (end_byte > 0xA9)) return true;
    8383        if (!UTF_16) {
    84         return (static_cast<unsigned char>(fileBuffer[fileSize-3]) != 0xE2) || (penult_byte != 0x80);
     84            return (static_cast<unsigned char>(fileBuffer[fileSize-3]) != 0xE2) || (penult_byte != 0x80);
    8585        }
    8686        else {// UTF_16
    87                 return (penult_byte != 0x20);
     87            return (penult_byte != 0x20);
    8888        }
    8989}
     
    126126void GrepEngine::grepCodeGen(std::string moduleName, re::RE * re_ast, bool CountOnly, bool UTF_16, bool isNameExpression) {
    127127    isUTF_16 = UTF_16;
    128         Module * M = new Module(moduleName, getGlobalContext());
     128    Module * M = new Module(moduleName, getGlobalContext());
    129129   
    130130    IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
     
    132132    kernel::PipelineBuilder pipelineBuilder(M, idb);
    133133
    134         Encoding::Type type;
    135         type = UTF_16 ? Encoding::Type::UTF_16 : Encoding::Type::UTF_8;
    136         unsigned bits;
    137         bits = UTF_16 ? 16 : 8;
    138 
    139         Encoding encoding(type, bits);
    140 
    141         mIsNameExpression = isNameExpression;
     134    Encoding::Type type;
     135    type = UTF_16 ? Encoding::Type::UTF_16 : Encoding::Type::UTF_8;
     136    unsigned bits;
     137    bits = UTF_16 ? 16 : 8;
     138
     139    Encoding encoding(type, bits);
     140
     141    mIsNameExpression = isNameExpression;
    142142    re_ast = re::regular_expression_passes(encoding, re_ast);   
    143143    pablo::PabloFunction * function = re::re2pablo_compiler(encoding, re_ast);
     
    178178    uint64_t finalLineUnterminated = 0;
    179179    if(finalLineIsUnterminated(mFileBuffer, mFileSize, isUTF_16))
    180         finalLineUnterminated = 1;   
     180    finalLineUnterminated = 1;   
    181181    mGrepFunction(mFileBuffer, mFileSize, 0, finalLineUnterminated);
    182182
     
    209209extern "C" {
    210210    void wrapped_report_match(uint64_t lineNum, uint64_t line_start, uint64_t line_end, const char * buffer, uint64_t filesize, int fileIdx) {
    211                 int index = isUTF_16 ? 2 : 1;
    212                 int idx = fileIdx;
    213        
     211        int index = isUTF_16 ? 2 : 1;
     212        int idx = fileIdx;
     213     
    214214        if (ShowFileNames) {
    215215            resultStrs[idx] << inputFiles[idx] << ':';
     
    236236        }
    237237        unsigned char end_byte = (unsigned char)buffer[line_end];
    238                 unsigned char penult_byte = (unsigned char)(buffer[line_end - 1]);
     238        unsigned char penult_byte = (unsigned char)(buffer[line_end - 1]);
    239239        if (NormalizeLineBreaks) {
    240240            if (end_byte == 0x85) {
     
    252252                // Check for line_end on first byte of CRLF;  note that we don't
    253253                // want to access past the end of buffer.
    254                                 if (line_end + 1 < filesize) {
    255                                         if (!isUTF_16 && buffer[line_end + 1] == 0x0A) {
    256                     // Found CRLF; preserve both bytes.
    257                                                 line_end++;;
    258                                         }
    259                                         if (isUTF_16 && buffer[line_end + 1] == 0x0 && buffer[line_end + 2] == 0x0A) {
    260                     // Found CRLF; preserve both bytes.
    261                                                 line_end += 2;
    262                                         }
    263                                 }
     254                if (line_end + 1 < filesize) {
     255                    if (!isUTF_16 && buffer[line_end + 1] == 0x0A) {
     256                    // Found CRLF; preserve both bytes.
     257                        line_end++;;
     258                    }
     259                    if (isUTF_16 && buffer[line_end + 1] == 0x0 && buffer[line_end + 2] == 0x0A) {
     260                    // Found CRLF; preserve both bytes.
     261                        line_end += 2;
     262                    }
     263                }
    264264            }
    265265            resultStrs[idx].write(&buffer[line_start * index], (line_end - line_start + 1) * index);
Note: See TracChangeset for help on using the changeset viewer.