Data Structures | |
| class | CMakeDiff |
| struct | CMakeDiff::IDiffCallback |
| struct | TClause |
| struct | TGetHashValue |
| struct | TGetIdentifier |
| struct | TGetWorksheetHashValue |
| struct | TGetWorksheetIdentifier |
| struct | TPhrase |
| struct | TPhraseDiffContext |
| struct | TStringDiffContext |
| struct | TStringInfo |
| struct | TTestItem |
| struct | TTestWorksheetItem |
| struct | TWordsDiffContext |
| struct | TWorksheet |
Typedefs | |
| typedef CMakeDiff< TPhrase, TPhraseDiffContext > | TPhraseDiff |
| typedef CMakeDiff< TStringInfo, TStringDiffContext > | TStringDiff |
| typedef CMakeDiff< TWorksheet::TRow, TWordsDiffContext, TGetWorksheetIdentifier, TGetWorksheetHashValue, TTestWorksheetItem > | TWorkSheetDiff |
Functions | |
| bool | loadExcelSheet (const string filename, TWorksheet &worksheet, bool checkUnique) |
| bool | loadStringFile (const std::string filename, vector< TStringInfo > &stringInfos, bool forceRehash, ucchar openMark, ucchar closeMark, bool specialCase) |
| void | makeHashCode (TWorksheet &sheet, bool forceRehash) |
| uint64 | makePhraseHash (const TPhrase &phrase) |
| bool | parseHashFromComment (const ucstring &comments, uint64 &hashValue) |
| ucstring | prepareExcelSheet (const TWorksheet &worksheet) |
| ucstring | preparePhraseFile (const std::vector< TPhrase > &phrases, bool removeDiffComments) |
| ucstring | preparePhraseFile (const vector< TPhrase > &phrases, bool removeDiffComments) |
| ucstring | prepareStringFile (const std::vector< TStringInfo > &strings, bool removeDiffComments) |
| ucstring | prepareStringFile (const vector< TStringInfo > &strings, bool removeDiffComments) |
| bool | readExcelSheet (const ucstring &str, TWorksheet &worksheet, bool checkUnique) |
| bool | readPhraseFile (const std::string &filename, vector< TPhrase > &phrases, bool forceRehash) |
| ucstring | tabLines (uint nbTab, const ucstring &str) |
Variables | |
| const ucstring | nl ("\r\n") |
|
|
Definition at line 493 of file diff_tool.h. |
|
|
Definition at line 492 of file diff_tool.h. |
|
|
Definition at line 494 of file diff_tool.h. |
|
||||||||||||||||
|
Definition at line 558 of file diff_tool.cpp. References NLMISC::CIFile::close(), nldebug, NLMISC::CIFile::open(), and readExcelSheet(). Referenced by NLMISC::CWordsDictionary::init().
00559 {
00560 // Yoyo: must test with CIFile because can be packed into a .bnp on client...
00561 CIFile fp;
00562 if(!fp.open(filename))
00563 {
00564 nldebug("DT: Can't open file [%s]\n", filename.c_str());
00565 return true;
00566 }
00567 fp.close();
00568
00569 ucstring str;
00570 CI18N::readTextFile(filename, str, false, false);
00571
00572 if (!readExcelSheet(str, worksheet, checkUnique))
00573 return false;
00574
00575 return true;
00576 }
|
|
||||||||||||||||||||||||||||
|
Definition at line 71 of file diff_tool.cpp. References STRING_MANAGER::TStringInfo::Comments, STRING_MANAGER::TStringInfo::HashValue, STRING_MANAGER::TStringInfo::Identifier, nlwarning, parseHashFromComment(), STRING_MANAGER::TStringInfo::Text, STRING_MANAGER::TStringInfo::Text2, ucchar, and uint.
00072 {
00073 /* uint8 *buffer = 0;
00074 uint size;
00075
00076 try
00077 {
00078 CIFile fp(filename);
00079 size = fp.getFileSize();
00080 buffer = new uint8[size];
00081 fp.serialBuffer(buffer, size);
00082 }
00083 catch(Exception &e)
00084 {
00085 nlinfo("Can't open file [%s] (%s)\n", filename.c_str(), e.what());
00086 return true;
00087 }
00088 */
00089 /* FILE *fp = fopen(filename.c_str(), "rb");
00090
00091 if (fp == NULL)
00092 {
00093 nlinfo("Can't open file [%s]\n", filename.c_str());
00094 if (buffer != 0)
00095 delete [] buffer;
00096 return true;
00097 }
00098
00099 // move to end of file
00100 fseek(fp, 0, SEEK_END);
00101
00102 fpos_t pos;
00103 fgetpos(fp, &pos);
00104
00105 uint8 *buffer = new uint8[uint(pos)];
00106
00107 rewind(fp);
00108 uint size = fread(buffer, 1, uint(pos), fp);
00109 fclose (fp);
00110 */
00111 ucstring text;
00112
00113 CI18N::readTextFile(filename, text, false, false, true);
00114 // CI18N::readTextBuffer(buffer, size, text);
00115 // delete [] buffer;
00116
00117 // ok, parse the file now.
00118 ucstring::const_iterator first(text.begin()), last(text.end());
00119 std::string lastLabel("nothing");
00120
00121 while (first != last)
00122 {
00123 TStringInfo si;
00124 CI18N::skipWhiteSpace(first, last, &si.Comments);
00125
00126 if (first == last)
00127 {
00128 // check if there is only swap command remaining in comment
00129 if (si.Comments.find(ucstring("// DIFF SWAP ")) != ucstring::npos)
00130 {
00131 stringInfos.push_back(si);
00132 }
00133 break;
00134 }
00135
00136 if (!CI18N::parseLabel(first, last, si.Identifier))
00137 {
00138 nlwarning("DT: Fatal : Invalid label will reading %s after %s\n", filename.c_str(), lastLabel.c_str());
00139 return false;
00140 }
00141 lastLabel = si.Identifier;
00142
00143 CI18N::skipWhiteSpace(first, last, &si.Comments);
00144
00145 if (!CI18N::parseMarkedString(openMark, closeMark, first, last, si.Text))
00146 {
00147 nlwarning("DT: Fatal : Invalid text value reading %s for label %s\n", filename.c_str(), lastLabel.c_str());
00148 return false;
00149 }
00150
00151 if (specialCase)
00152 {
00153 CI18N::skipWhiteSpace(first, last, &si.Comments);
00154
00155 if (!CI18N::parseMarkedString(openMark, closeMark, first, last, si.Text2))
00156 {
00157 nlwarning("DT: Fatal : Invalid text2 value reading %s for label %s\n", filename.c_str(), lastLabel.c_str());
00158 return false;
00159 }
00160
00161 }
00162
00163 if (forceRehash || !parseHashFromComment(si.Comments, si.HashValue))
00164 {
00165 // compute the hash value from text.
00166 si.HashValue = CI18N::makeHash(si.Text);
00167 // nldebug("Generating hash for %s as %s", si.Identifier.c_str(), CI18N::hashToString(si.HashValue).c_str());
00168 }
00169 else
00170 {
00171 // nldebug("Comment = [%s]", si.Comments.toString().c_str());
00172 // nldebug("Retreiving hash for %s as %s", si.Identifier.c_str(), CI18N::hashToString(si.HashValue).c_str());
00173 }
00174 stringInfos.push_back(si);
00175 }
00176
00177
00178 // check identifier uniqueness
00179 {
00180 bool error = false;
00181 set<string> unik;
00182 set<string>::iterator it;
00183 for (uint i=0; i<stringInfos.size(); ++i)
00184 {
00185 it = unik.find(stringInfos[i].Identifier);
00186 if (it != unik.end())
00187 {
00188 nlwarning("DT: loadStringFile : identifier '%s' exist twice", stringInfos[i].Identifier.c_str() );
00189 error = true;
00190 }
00191 else
00192 unik.insert(stringInfos[i].Identifier);
00193
00194 }
00195 if (error)
00196 return false;
00197 }
00198
00199 return true;
00200 }
|
|
||||||||||||
|
Definition at line 749 of file diff_tool.cpp. References STRING_MANAGER::TWorksheet::ColCount, STRING_MANAGER::TWorksheet::Data, index, STRING_MANAGER::TWorksheet::insertColumn(), uint, and uint64.
00750 {
00751 if (!sheet.Data.empty())
00752 {
00753 TWorksheet::TRow::iterator it = find(sheet.Data[0].begin(), sheet.Data[0].end(), ucstring("*HASH_VALUE"));
00754 if (forceRehash || it == sheet.Data[0].end())
00755 {
00756 // we need to generate HASH_VALUE column !
00757 if (it == sheet.Data[0].end())
00758 {
00759 sheet.insertColumn(0);
00760 sheet.Data[0][0] = ucstring("*HASH_VALUE");
00761 }
00762
00763 // Check columns
00764 vector<bool> columnOk;
00765 columnOk.resize(sheet.ColCount, false);
00766 for (uint k=1; k<sheet.ColCount; ++k)
00767 {
00768 if (sheet.Data[0][k].find(ucstring("*")) != 0 && sheet.Data[0][k].find(ucstring("DIFF ")) != 0)
00769 {
00770 columnOk[k]= true;
00771 }
00772 }
00773
00774 // make hash for each line
00775 ucstring str;
00776 for (uint j=1; j<sheet.Data.size(); ++j)
00777 {
00778 str.erase();
00779 for (uint k=1; k<sheet.ColCount; ++k)
00780 {
00781 if (columnOk[k])
00782 {
00783 str += sheet.Data[j][k];
00784 }
00785 }
00786 uint64 hash = CI18N::makeHash(str);
00787 CI18N::hashToUCString(hash, sheet.Data[j][0]);
00788 }
00789 }
00790 else
00791 {
00792 uint index = it - sheet.Data[0].begin();
00793 for (uint j=1; j<sheet.Data.size(); ++j)
00794 {
00795 ucstring &field = sheet.Data[j][index];
00796
00797 if (!field.empty() && field[0] == '_')
00798 field = field.substr(1);
00799 }
00800 }
00801 }
00802 }
|
|
|
Definition at line 37 of file diff_tool.cpp. References STRING_MANAGER::TPhrase::Clauses, STRING_MANAGER::TPhrase::Parameters, uint, and uint64. Referenced by readPhraseFile().
00038 {
00039 ucstring text;
00040 text = phrase.Parameters;
00041 for (uint i=0; i<phrase.Clauses.size(); ++i)
00042 {
00043 text += phrase.Clauses[i].Conditions;
00044 text += phrase.Clauses[i].Identifier;
00045 text += phrase.Clauses[i].Text;
00046 }
00047
00048 return CI18N::makeHash(text);
00049 }
|
|
||||||||||||
|
Definition at line 54 of file diff_tool.cpp. References ucstring::toString(), and uint64. Referenced by loadStringFile(), and readPhraseFile().
00055 {
00056 string str = comments.toString();
00057
00058 string::size_type pos = str.find("HASH_VALUE ");
00059 if (pos == string::npos)
00060 return false;
00061
00062 string hashStr = str.substr(pos + 11, 16);
00063
00064 hashValue = CI18N::stringToHash(hashStr);
00065 return true;
00066 }
|
|
|
Definition at line 804 of file diff_tool.cpp. References STRING_MANAGER::TWorksheet::Data, nl, and uint.
00805 {
00806 if(worksheet.Data.empty())
00807 return ucstring();
00808
00809 // **** First pass: count approx the size
00810 uint approxSize= 0;
00811 for (uint i=0; i<worksheet.Data.size(); ++i)
00812 {
00813 for (uint j=0; j<worksheet.Data[i].size(); ++j)
00814 {
00815 approxSize+= worksheet.Data[i][j].size() + 1;
00816 }
00817 approxSize++;
00818 }
00819
00820 // Hash value for each column?
00821 vector<bool> hashValue;
00822 hashValue.resize(worksheet.Data[0].size());
00823 for (uint j=0; j<worksheet.Data[0].size(); ++j)
00824 {
00825 hashValue[j]= worksheet.Data[0][j] == ucstring("*HASH_VALUE");
00826 }
00827
00828 // **** Second pass: fill
00829 ucstring text;
00830 text.reserve(approxSize*2);
00831 for (uint i=0; i<worksheet.Data.size(); ++i)
00832 {
00833 for (uint j=0; j<worksheet.Data[i].size(); ++j)
00834 {
00835 if (i > 0 && hashValue[j])
00836 text += "_";
00837 text += worksheet.Data[i][j];
00838 if (j != worksheet.Data[i].size()-1)
00839 text += '\t';
00840 }
00841 text += nl;
00842 }
00843
00844 return text;
00845 }
|
|
||||||||||||
|
|
|
||||||||||||
|
Definition at line 472 of file diff_tool.cpp. References STRING_MANAGER::TPhrase::Clauses, comment(), STRING_MANAGER::TClause::Comments, STRING_MANAGER::TPhrase::Comments, STRING_MANAGER::TClause::Conditions, NLMISC::explode(), STRING_MANAGER::TPhrase::HashValue, STRING_MANAGER::TClause::Identifier, STRING_MANAGER::TPhrase::Identifier, nl, STRING_MANAGER::TPhrase::Parameters, tabLines(), STRING_MANAGER::TClause::Text, ucstring::toString(), and uint.
00473 {
00474 ucstring ret;
00475 vector<TPhrase>::const_iterator first(phrases.begin()), last(phrases.end());
00476 for (; first != last; ++first)
00477 {
00478 const TPhrase &p = *first;
00479
00480 if (removeDiffComments)
00481 {
00482 string comment = p.Comments.toString();
00483 vector<string> lines;
00484 explode(comment, "\n", lines, true);
00485
00486 uint i;
00487 for (i=0; i<lines.size(); ++i)
00488 {
00489 if (lines[i].find("// DIFF ") != string::npos)
00490 {
00491 lines.erase(lines.begin()+i);
00492 --i;
00493 }
00494 }
00495
00496 comment.erase();
00497 for (i=0; i<lines.size(); ++i)
00498 {
00499 comment += lines[i] + "\n";
00500 }
00501 p.Comments = ucstring(comment);
00502 }
00503 ret += p.Comments;
00504
00505 if (!p.Identifier.empty() || !p.Clauses.empty())
00506 {
00507 if (p.Comments.find(ucstring("// HASH_VALUE ")) == ucstring::npos)
00508 {
00509 // add the hash value.
00510 ret += ucstring("// HASH_VALUE ")+CI18N::hashToString(p.HashValue) + nl;
00511 }
00512 ret += p.Identifier + " ("+p.Parameters + ")" + nl;
00513 ret += '{';
00514 ret += nl;
00515 for (uint i=0; i<p.Clauses.size(); ++i)
00516 {
00517 const TClause &c = p.Clauses[i];
00518 if (!c.Comments.empty())
00519 {
00520 ucstring comment = tabLines(1, c.Comments);
00521 ret += comment; // + '\r'+'\n';
00522 }
00523 if (!c.Conditions.empty())
00524 {
00525 ucstring cond = tabLines(1, c.Conditions);
00526 ret += cond + nl;
00527 }
00528 ret += '\t';
00529 // ucstring text = CI18N::makeMarkedString('[', ']', c.Text);
00530
00531 ucstring text = CI18N::makeMarkedString('[', ']', c.Text);;
00532 ucstring text2;
00533 // add new line and tab after each \n tag
00534 ucstring::size_type pos;
00535 const ucstring nlTag("\\n");
00536 while ((pos = text.find(nlTag)) != ucstring::npos)
00537 {
00538 text2 += text.substr(0, pos+2) + nl;
00539 text = text.substr(pos+2);
00540 }
00541 text2 += text;//.substr(0, pos+2);
00542
00543 text.swap(text2);
00544
00545 text = tabLines(3, text);
00546 // remove begin tabs
00547 text = text.substr(3);
00548 ret += '\t' + c.Identifier + '\t' + text + nl + nl;
00549 }
00550 ret += '}';
00551 }
00552 ret += nl + nl;
00553 }
00554
00555 return ret;
00556 }
|
|
||||||||||||
|
|
|
||||||||||||
|
Definition at line 203 of file diff_tool.cpp. References comment(), STRING_MANAGER::TStringInfo::Comments, NLMISC::explode(), STRING_MANAGER::TStringInfo::HashValue, STRING_MANAGER::TStringInfo::Identifier, nl, STRING_MANAGER::TStringInfo::Text, NLMISC::toString(), ucstring::toString(), and uint.
00204 {
00205 ucstring diff;
00206
00207 vector<TStringInfo>::const_iterator first(strings.begin()), last(strings.end());
00208 for (; first != last; ++first)
00209 {
00210 ucstring str;
00211 const TStringInfo &si = *first;
00212 string comment = si.Comments.toString();
00213 vector<string> lines;
00214 explode(comment, "\n", lines, true);
00215
00216 uint i;
00217 for (i=0; i<lines.size(); ++i)
00218 {
00219 if (removeDiffComments)
00220 {
00221 if (lines[i].find("// DIFF ") != string::npos)
00222 {
00223 lines.erase(lines.begin()+i);
00224 --i;
00225 continue;
00226 }
00227 }
00228 if (lines[i].find("// INDEX ") != string::npos)
00229 {
00230 lines.erase(lines.begin()+i);
00231 --i;
00232 }
00233 else if (lines[i].find("// HASH_VALUE ") != string::npos)
00234 {
00235 lines.erase(lines.begin()+i);
00236 --i;
00237 }
00238 }
00239
00240 comment.erase();
00241 for (i=0; i<lines.size(); ++i)
00242 {
00243 comment += lines[i] + "\n";
00244 }
00245 si.Comments = ucstring(comment);
00246
00247 str = si.Comments;
00248 if (!si.Identifier.empty() || !si.Text.empty())
00249 {
00250 // add hash value comment if needed
00251 // if (si.Comments.find(ucstring("// HASH_VALUE ")) == ucstring::npos)
00252 str += ucstring("// HASH_VALUE ") + CI18N::hashToString(si.HashValue)+ nl;
00253 str += ucstring("// INDEX ") + NLMISC::toString("%u", first-strings.begin())+ nl;
00254 str += si.Identifier + '\t';
00255
00256 ucstring text = CI18N::makeMarkedString('[', ']', si.Text);;
00257 ucstring text2;
00258 // add new line and tab after each \n tag
00259 ucstring::size_type pos;
00260 const ucstring nlTag("\\n");
00261 while ((pos = text.find(nlTag)) != ucstring::npos)
00262 {
00263 text2 += text.substr(0, pos+2) + nl + "\t";
00264 text = text.substr(pos+2);
00265 }
00266 text2 += text;//.substr(0, pos+2);
00267 str += text2 + nl + nl;
00268 // str += CI18N::makeMarkedString('[', ']', si.Text) + nl + nl;
00269 }
00270
00271 // nldebug("Adding string [%s]", str.toString().c_str());
00272 diff += str;
00273 }
00274
00275 return diff;
00276 }
|
|
||||||||||||||||
|
append last cell Definition at line 578 of file diff_tool.cpp. References STRING_MANAGER::TWorksheet::ColCount, STRING_MANAGER::TWorksheet::getData(), STRING_MANAGER::TWorksheet::insertColumn(), nl, nlassert, nlwarning, STRING_MANAGER::TWorksheet::resize(), STRING_MANAGER::TWorksheet::setData(), STRING_MANAGER::TWorksheet::size(), ucstring::toString(), ucchar, uint, and uint16. Referenced by loadExcelSheet().
00579 {
00580 if(str.empty())
00581 return true;
00582
00583 // copy the str to a big ucchar array => Avoid allocation / free
00584 vector<ucchar> strArray;
00585 // append a '\0'
00586 strArray.resize(str.size()+1);
00587 strArray[strArray.size()-1]= 0;
00588 memcpy(&strArray[0], &str[0], str.size()*sizeof(ucchar));
00589
00590
00591 // **** Build array of lines. just point to strArray, and fill 0 where appropriated
00592 vector<ucchar*> lines;
00593 lines.reserve(500);
00594 ucstring::size_type pos = 0;
00595 ucstring::size_type lastPos = 0;
00596 while ((pos = str.find(nl, lastPos)) != ucstring::npos)
00597 {
00598 if (pos>lastPos)
00599 {
00600 strArray[pos]= 0;
00601 // nldebug("Found line : [%s]", ucstring(&strArray[lastPos]).toString().c_str());
00602 lines.push_back(&strArray[lastPos]);
00603 }
00604 lastPos = pos + 2;
00605 }
00606
00607 // Must add last line if no \r\n ending
00608 if (lastPos < str.size())
00609 {
00610 pos= str.size();
00611 strArray[pos]= 0;
00612 // nldebug("Found line : [%s]", ucstring(&strArray[lastPos]).toString().c_str());
00613 lines.push_back(&strArray[lastPos]);
00614 }
00615
00616 // nldebug("Found %u lines", lines.size());
00617
00618 // **** Do 2 pass.1st count the cell number, then fill. => avoid reallocation
00619 uint newColCount= 0;
00620 uint i;
00621 for (i=0; i<lines.size(); ++i)
00622 {
00623 uint numCells;
00624 numCells= 0;
00625
00626 ucchar *first= lines[i];
00627 for (; *first != 0; ++first)
00628 {
00629 if (*first == '\t')
00630 {
00631 numCells++;
00632 }
00633 else if (*first == '"' && first==lines[i])
00634 {
00635 // read a quoted field.
00636 first++;
00637 while (*first != 0 && *first != '"' && *(first+1) != 0 && *(first+1) != '"')
00638 {
00639 first++;
00640 if (*first != 0 && *first == '"')
00641 {
00642 // skip this
00643 first++;
00644 }
00645 }
00646 }
00647 }
00648 // last cell
00649 numCells++;
00650
00651 // take max cell of all lines
00652 newColCount= max(newColCount, numCells);
00653 }
00654
00655
00656 // **** alloc / enlarge worksheet
00657 // enlarge Worksheet column size, as needed
00658 while (worksheet.ColCount < newColCount)
00659 worksheet.insertColumn(worksheet.ColCount);
00660
00661 // enlarge Worksheet row size, as needed
00662 uint startLine= worksheet.size();
00663 worksheet.resize(startLine + lines.size());
00664
00665
00666 // **** fill worksheet
00667 ucstring cell;
00668 for (i=0; i<lines.size(); ++i)
00669 {
00670 uint numCells;
00671 numCells= 0;
00672 cell.erase();
00673
00674 ucchar *first= lines[i];
00675 for (; *first != 0; ++first)
00676 {
00677 if (*first == '\t')
00678 {
00679 // nldebug("Found cell [%s]", cell.toString().c_str());
00680 worksheet.setData(startLine + i, numCells, cell);
00681 numCells++;
00682 cell.erase();
00683 }
00684 else if (*first == '"' && first==lines[i])
00685 {
00686 // read a quoted field.
00687 first++;
00688 while (*first != 0 && *first != '"' && *(first+1) != 0 && *(first+1) != '"')
00689 {
00690 cell += *first;
00691 first++;
00692 if (*first != 0 && *first == '"')
00693 {
00694 // skip this
00695 first++;
00696 }
00697 }
00698 }
00699 else
00700 {
00701 cell += *first;
00702 }
00703 }
00704 // nldebug("Found cell [%s]", cell.toString().c_str());
00706 worksheet.setData(startLine + i, numCells, cell);
00707 numCells++;
00708 nlassert(numCells<=newColCount);
00709 // nldebug("Found %u cells in line %u", numCells, i);
00710 }
00711
00712
00713 // **** identifier uniqueness checking.
00714 if (checkUnique)
00715 {
00716 if (worksheet.size() > 0)
00717 {
00718 // look for the first non '* tagged' or 'DIFF_CMD' column
00719 uint nameCol = 0;
00720 while (nameCol < worksheet.ColCount && (*worksheet.getData(0, nameCol).begin() == uint16('*') || worksheet.getData(0, nameCol) == ucstring("DIFF_CMD")))
00721 ++nameCol;
00722
00723 if (nameCol < worksheet.ColCount )
00724 {
00725 // ok we can check unikness
00726 bool error = false;
00727 set<ucstring> unik;
00728 set<ucstring>::iterator it;
00729 for (uint j=0; j<worksheet.size(); ++j)
00730 {
00731 it = unik.find(worksheet.getData(j, nameCol));
00732 if (it != unik.end())
00733 {
00734 nlwarning("DT: loadStringFile : identifier '%s' exist twice", worksheet.getData(j, nameCol).toString().c_str() );
00735 error = true;
00736 }
00737 else
00738 unik.insert(worksheet.getData(j, nameCol));
00739 }
00740 if (error)
00741 return false;
00742 }
00743 }
00744 }
00745
00746 return true;
00747 }
|
|
||||||||||||||||
|
Definition at line 279 of file diff_tool.cpp. References STRING_MANAGER::TPhrase::Clauses, STRING_MANAGER::TClause::Comments, STRING_MANAGER::TPhrase::Comments, STRING_MANAGER::TClause::Conditions, STRING_MANAGER::TPhrase::HashValue, STRING_MANAGER::TClause::Identifier, STRING_MANAGER::TPhrase::Identifier, makePhraseHash(), nlwarning, STRING_MANAGER::TPhrase::Parameters, parseHashFromComment(), STRING_MANAGER::TClause::Text, and uint.
00280 {
00281 ucstring doc;
00282
00283 CI18N::readTextFile(filename, doc, false, false, true);
00284
00285 // CI18N::writeTextFile("test.txt", doc, false);
00286
00287 /* uint8 *buffer = 0;
00288 uint size;
00289 */
00290
00291 /* try
00292 {
00293 CIFile fp(filename);
00294 size = fp.getFileSize();
00295 buffer = new uint8[size];
00296 fp.serialBuffer(buffer, size);
00297 }
00298 catch(Exception &e)
00299 {
00300 nlinfo("Can't open file [%s] (%s)\n", filename.c_str(), e.what());
00301 return true;
00302 }
00303 */
00304 /* FILE *fp = fopen(filename.c_str(), "rb");
00305 if (fp == 0)
00306 {
00307 nlinfo("Could't not open %s\n", filename.c_str());
00308 return true;
00309 }
00310 uint size = CFile::getFileSize(fp);
00311 uint8 *buffer = new uint8[size];
00312 fread(buffer, 1, size, fp);
00313 fclose(fp);
00314 */
00315 /* CI18N::readTextBuffer(buffer, size, doc);
00316 delete [] buffer;
00317 */
00318 std::string lastRead("nothing");
00319
00320 ucstring::const_iterator first(doc.begin()), last(doc.end());
00321 while (first != last)
00322 {
00323 TPhrase phrase;
00324 // parse the phrase
00325 CI18N::skipWhiteSpace(first, last, &phrase.Comments);
00326
00327 if (first == last)
00328 break;
00329 if (!CI18N::parseLabel(first, last, phrase.Identifier))
00330 {
00331 nlwarning("DT: Error parsing phrase identifier after %s\n", lastRead.c_str());
00332 return false;
00333 }
00334 // nldebug("DT: parsing phrase '%s'", phrase.Identifier.c_str());
00335 lastRead = phrase.Identifier;
00336 CI18N::skipWhiteSpace(first, last, &phrase.Comments);
00337 if (!CI18N::parseMarkedString('(', ')', first, last, phrase.Parameters))
00338 {
00339 nlwarning("DT: Error parsing parameter list for phrase %s\n", phrase.Identifier.c_str());
00340 return false;
00341 }
00342 CI18N::skipWhiteSpace(first, last, &phrase.Comments);
00343 if (first == last || *first != '{')
00344 {
00345 nlwarning("DT: Error parsing block opening '{' in phase %s\n", phrase.Identifier.c_str());
00346 return false;
00347 }
00348 ++first;
00349
00350 ucstring temp;
00351
00352 while (first != last && *first != '}')
00353 {
00354 TClause clause;
00355 // append the comment preread at previous pass
00356 clause.Comments = temp;
00357 temp.erase();
00358 // parse the clauses
00359 CI18N::skipWhiteSpace(first, last, &clause.Comments);
00360 if (first == last)
00361 {
00362 nlwarning("DT: Found end of file in non closed block for phrase %s\n", phrase.Identifier.c_str());
00363 return false;
00364 }
00365
00366 if (*first == '}')
00367 break;
00368
00369 // skip the conditionnal expression
00370 ucstring cond;
00371 while (first != last && *first == '(')
00372 {
00373 if (!CI18N::parseMarkedString('(', ')', first, last, cond))
00374 {
00375 nlwarning("DT: Error parsing conditionnal expression in phrase %s, clause %u\n", phrase.Identifier.c_str(), phrase.Clauses.size()+1);
00376 return false;
00377 }
00378 clause.Conditions += "(" + cond + ") ";
00379 CI18N::skipWhiteSpace(first, last, &clause.Comments);
00380 }
00381 if (first == last)
00382 {
00383 nlwarning("DT: Found end of file in non closed block for phrase %s\n", phrase.Identifier.c_str());
00384 return false;
00385 }
00386 // read the idnetifier (if any)
00387 CI18N::parseLabel(first, last, clause.Identifier);
00388 CI18N::skipWhiteSpace(first, last, &temp);
00389 // read the text
00390 if (CI18N::parseMarkedString('[', ']', first, last, clause.Text))
00391 {
00392 // the last read comment is for this clause.
00393 clause.Comments += temp;
00394 temp.erase();
00395 }
00396 else
00397 {
00398 nlwarning("DT: Error reading text for clause %u (%s) in phrase %s\n",
00399 phrase.Clauses.size()+1,
00400 clause.Identifier.c_str(),
00401 phrase.Identifier.c_str());
00402 return false;
00403
00404 }
00405
00406 phrase.Clauses.push_back(clause);
00407 }
00408 CI18N::skipWhiteSpace(first, last);
00409 if (first == last || *first != '}')
00410 {
00411 nlwarning("DT: Missing block clogin tag '}' in phrase %s\n", phrase.Identifier.c_str());
00412 return false;
00413 }
00414 ++first;
00415
00416 // handle hash value.
00417 if (forceRehash || !parseHashFromComment(phrase.Comments, phrase.HashValue))
00418 {
00419 // the hash is not in the comment, compute it.
00420 phrase.HashValue = makePhraseHash(phrase);
00421 }
00422
00423 // nldebug("DT : storing phrase '%s'", phrase.Identifier.c_str());
00424 phrases.push_back(phrase);
00425 }
00426
00427 // check identifier uniqueness
00428 {
00429 bool error = false;
00430 set<string> unik;
00431 set<string>::iterator it;
00432 for (uint i=0; i<phrases.size(); ++i)
00433 {
00434 it = unik.find(phrases[i].Identifier);
00435 if (it != unik.end())
00436 {
00437 nlwarning("DT: loadStringFile : identifier '%s' exist twice", phrases[i].Identifier.c_str() );
00438 error = true;
00439 }
00440 else
00441 unik.insert(phrases[i].Identifier);
00442 }
00443 if (error)
00444 return false;
00445 }
00446
00447 return true;
00448 }
|
|
||||||||||||
|
Definition at line 449 of file diff_tool.cpp. References uint. Referenced by preparePhraseFile().
00450 {
00451 ucstring ret;
00452 ucstring tabs;
00453
00454 for (uint i =0; i<nbTab; ++i)
00455 tabs.push_back('\t');
00456
00457 ret = tabs;
00458 ucstring::const_iterator first(str.begin()), last(str.end());
00459 for (; first != last; ++first)
00460 {
00461 ret += *first;
00462 if (*first == '\n')
00463 ret += tabs;
00464 }
00465
00466 while (ret[ret.size()-1] == '\t')
00467 ret = ret.substr(0, ret.size()-1);
00468
00469 return ret;
00470 }
|
|
|
Referenced by prepareExcelSheet(), preparePhraseFile(), prepareStringFile(), and readExcelSheet(). |
1.3.6