nsresult nsScanner::ReadUntil(nsScannerIterator& aStart, nsScannerIterator& aEnd, const nsReadEndCondition &aEndCondition, PRBool addTerminal) { if (!mSlidingBuffer) { return kEOF; } nsScannerIterator origin, current; const PRUnichar* setstart = aEndCondition.mChars; const PRUnichar* setcurrent; origin = mCurrentPosition; current = origin; PRUnichar theChar=0; nsresult result=Peek(theChar); if (NS_FAILED(result)) { aStart = aEnd = current; return result; } while (current != mEndPosition) { if (theChar == '\0') { ReplaceCharacter(current, sInvalid); theChar = sInvalid; } // Filter out completely wrong characters // Check if all bits are in the required area if(!(theChar & aEndCondition.mFilter)) { // They were. Do a thorough check. setcurrent = setstart; while (*setcurrent) { if (*setcurrent == theChar) { if(addTerminal) ++current; aStart = origin; aEnd = current; SetPosition(current); return NS_OK; } ++setcurrent; } } ++current; theChar = *current; } // If we are here, we didn't find any terminator in the string and // current = mEndPosition SetPosition(current); aStart = origin; aEnd = current; return FillBuffer(); }
/** * Consume characters until you run into space, a '<', a '>', or a '/'. * * @param aString - receives new data from stream * @return error code */ nsresult nsScanner::ReadTagIdentifier(nsScannerSharedSubstring& aString) { if (!mSlidingBuffer) { return kEOF; } PRUnichar theChar=0; nsresult result=Peek(theChar); nsScannerIterator current, end; PRBool found=PR_FALSE; current = mCurrentPosition; end = mEndPosition; // Loop until we find an illegal character. Everything is then appended // later. while(current != end && !found) { theChar=*current; switch(theChar) { case '\n': case '\r': case ' ' : case '\b': case '\t': case '\v': case '\f': case '<': case '>': case '/': found = PR_TRUE; break; case '\0': ReplaceCharacter(current, sInvalid); break; default: break; } if (!found) { ++current; } } // Don't bother appending nothing. if (current != mCurrentPosition) { AppendUnicodeTo(mCurrentPosition, current, aString); } SetPosition(current); if (current == end) { result = FillBuffer(); } //DoErrTest(aString); return result; }
void nsScanner::OverrideReplacementCharacter(PRUnichar aReplacementCharacter) { mReplacementCharacter = aReplacementCharacter; if (mHasInvalidCharacter) { ReplaceCharacter(mFirstInvalidPosition, mReplacementCharacter); } }
/** * Consume chars as long as they are <i>in</i> the * given validSet of input chars. * * @update gess 3/25/98 * @param aString will contain the result of this method * @param aValidSet is an ordered string that contains the * valid characters * @return error code */ nsresult nsScanner::ReadWhile(nsString& aString, nsString& aValidSet, PRBool addTerminal){ if (!mSlidingBuffer) { return kEOF; } PRUnichar theChar=0; nsresult result=Peek(theChar); nsScannerIterator origin, current, end; origin = mCurrentPosition; current = origin; end = mEndPosition; while(current != end) { theChar=*current; if (theChar == '\0') { ReplaceCharacter(current, sInvalid); theChar = sInvalid; } if(theChar) { PRInt32 pos=aValidSet.FindChar(theChar); if(kNotFound==pos) { if(addTerminal) ++current; AppendUnicodeTo(origin, current, aString); break; } } ++current; } SetPosition(current); if (current == end) { AppendUnicodeTo(origin, current, aString); return FillBuffer(); } //DoErrTest(aString); return result; }
/** * Consumes chars until you see the given terminalChar * * @update gess 3/25/98 * @param * @return error code */ nsresult nsScanner::ReadUntil(nsAString& aString, PRUnichar aTerminalChar, PRBool addTerminal) { if (!mSlidingBuffer) { return kEOF; } nsScannerIterator origin, current; origin = mCurrentPosition; current = origin; PRUnichar theChar; nsresult result = Peek(theChar); if (NS_FAILED(result)) { return result; } while (current != mEndPosition) { if (theChar == '\0') { ReplaceCharacter(current, sInvalid); theChar = sInvalid; } if (aTerminalChar == theChar) { if(addTerminal) ++current; AppendUnicodeTo(origin, current, aString); SetPosition(current); return NS_OK; } ++current; theChar = *current; } // If we are here, we didn't find any terminator in the string and // current = mEndPosition AppendUnicodeTo(origin, current, aString); SetPosition(current); return FillBuffer(); }
BOOL _XCollectionManager::LoadCollectionItem(FILE* fileptr) { if(!fileptr) return FALSE; Release(); TCHAR buffer[512]; int totalcount = 0; int index = 0; int collectionlistlinecount = 0; // int explainlinecount = 0; int currentexplainlinecount = 0; int currentneeditemcount = 0; int rewardsetcount = 0; int currentrewardsetcount = 0; int rewarditemcount = 0; int currentrewarditemcount = 0; BOOL bReadCount = FALSE; BOOL bNewitem = FALSE; _XCollectionItem* newcollection = NULL; _XCollectionRewardSet* newrewardset = NULL; do { if(feof(fileptr)) break; memset(buffer, 0, sizeof(buffer)); if(!fgets(buffer, 511, fileptr)) break; if(strncmp(buffer, _T("_XM_EOS"), 7) == 0) break; if((strlen(buffer) > 0) && buffer[0] != _T(';') && buffer[0] != _T('\n') && buffer[0] != _T('\r')) { if(!bReadCount) { sscanf(buffer, "%d", &totalcount); totalcount++; bReadCount = TRUE; collectionlistlinecount++; } else { if(!bNewitem) { newcollection = new _XCollectionItem; bNewitem = TRUE; // explainlinecount = 0; currentexplainlinecount = 0; currentneeditemcount = 0; rewardsetcount = 0; currentrewardsetcount = 0; rewarditemcount = 0; currentrewarditemcount = 0; } if( collectionlistlinecount == 1 ) // 수집품 고유 인덱스 { sscanf(buffer, "%d", &newcollection->m_CollectionIndex ); index++; collectionlistlinecount++; } else if( collectionlistlinecount == 2 ) // 선행으로 완료해야 할 명품 수집품 고유 인덱스 5개 { //sscanf(buffer, "%d", &newcollection->m_CollectionVersion ); sscanf(buffer, "%d %d %d %d %d", &newcollection->m_PrecedeCollectionIndex[0], &newcollection->m_PrecedeCollectionIndex[1], &newcollection->m_PrecedeCollectionIndex[2], &newcollection->m_PrecedeCollectionIndex[3], &newcollection->m_PrecedeCollectionIndex[4]); collectionlistlinecount++; } else if( collectionlistlinecount == 3 ) // 수집품 타입 (하품, 중품, 상품, 명품 등을 구분한다.) { sscanf(buffer, "%d", &newcollection->m_CollectionType ); collectionlistlinecount++; } else if( collectionlistlinecount == 4 ) // 수집품 가능 최소레벨 { sscanf(buffer, "%d", &newcollection->m_CollectionMinimumLevel ); collectionlistlinecount++; } else if( collectionlistlinecount == 5 ) // 수집품 이름 (가죽수집, 약초수집) { #ifdef _XTS_NEWLIFEWINDOW int strlength = strlen(buffer); newcollection->m_CollectionName = new TCHAR[strlength+1]; newcollection->m_CollectionName[strlength] = 0; strncpy(newcollection->m_CollectionName, buffer, strlength); #else memset( newcollection->m_CollectionName, 0, sizeof(TCHAR)*128 ); strncpy( newcollection->m_CollectionName, buffer, sizeof(TCHAR)*128 ); #endif collectionlistlinecount++; } else if( collectionlistlinecount == 6 ) // 수집품 보상 내용 라인 수 (최대라인수 3줄) { #ifdef _XTS_NEWLIFEWINDOW #else memset( newcollection->m_CollectionExplain, 0, sizeof(TCHAR)*_XDEF_MAX_COLLECTION_LINE*512 ); #endif sscanf(buffer, "%d", &newcollection->m_CollectionExplainLineCount); collectionlistlinecount++; } else if( collectionlistlinecount == 7 ) // 수집품 보상 내용 { #ifdef _XTS_NEWLIFEWINDOW newcollection->m_TempString[currentexplainlinecount] = new TCHAR[512]; memset(newcollection->m_TempString[currentexplainlinecount], 0, sizeof(TCHAR)*512); //strncpy( newcollection->m_TempString[currentexplainlinecount], buffer, sizeof(TCHAR)*512 ); strcpy( newcollection->m_TempString[currentexplainlinecount], buffer ); //OutputDebugString( newcollection->m_TempString[currentexplainlinecount] ); #else strncpy( newcollection->m_CollectionExplain[currentexplainlinecount], buffer, sizeof(TCHAR)*512 ); #endif currentexplainlinecount++; if( currentexplainlinecount == newcollection->m_CollectionExplainLineCount ) collectionlistlinecount++; } else if( collectionlistlinecount == 8 ) // 수집해야 할 아이템 갯수 { #ifdef _XTS_NEWLIFEWINDOW int strlength = 0; for(int i = 0 ; i < _XDEF_MAX_COLLECTION_LINE ; i++) { if(newcollection->m_TempString[i]) { ReplaceCharacter(newcollection->m_TempString[i], _T('\r'), _T(' ')); ReplaceCharacter(newcollection->m_TempString[i], _T('\n'), _T(' ')); ReplaceCharacter(newcollection->m_TempString[i], _T('\t'), _T(' ')); strlength += strlen(newcollection->m_TempString[i]); } } newcollection->m_CollectionExplain = new TCHAR[strlength+1]; memset(newcollection->m_CollectionExplain, 0, sizeof(TCHAR)*(strlength+1)); for(i = 0 ; i < _XDEF_MAX_COLLECTION_LINE ; i++) { if(newcollection->m_TempString[i]) { strcat(newcollection->m_CollectionExplain, newcollection->m_TempString[i]); } } // _XDWINPRINT("%s", newcollection->m_CollectionExplain); for(i = 0 ; i < _XDEF_MAX_COLLECTION_LINE ; i++) { SAFE_DELETE_ARRAY(newcollection->m_TempString[i]); } #endif sscanf(buffer, "%d", &newcollection->m_NeedItemTotalCount ); collectionlistlinecount++; } else if( collectionlistlinecount == 9 ) // 수집해야 할 아이템 { _XCollectionResourceItem* newneeditem = new _XCollectionResourceItem; short itemid; int cType = 0; unsigned int ucCount = 0; sscanf(buffer, "%d %d %d %d", &newneeditem->m_Index, &cType, &itemid, &ucCount); newneeditem->Set_m_sID(itemid); newneeditem->Set_m_cType(cType); newneeditem->Set_m_ucCount(ucCount); newneeditem->Set_m_cSecond( _XGameItem::GetItemSecond( newneeditem->Get_m_cType(), newneeditem->Get_m_sID()) ); newcollection->m_listNeedItem.push_back( newneeditem ); currentneeditemcount++; if( currentneeditemcount == newcollection->m_NeedItemTotalCount ) collectionlistlinecount++; } else if( collectionlistlinecount == 10 ) // 보상 세트 갯수 { sscanf(buffer, "%d", &rewardsetcount); collectionlistlinecount++; } else if( collectionlistlinecount == 11 ) // 보상 세트 인덱스 { newrewardset = new _XCollectionRewardSet; sscanf(buffer, "%d", &newrewardset->m_Index); collectionlistlinecount++; } else if( collectionlistlinecount == 12 ) // 보상 아이템 갯수 { sscanf(buffer, "%d", &rewarditemcount); collectionlistlinecount = 13; } else if( collectionlistlinecount == 13 ) // 보상 아이템 { _XCollectionResourceItem* newrewarditem = new _XCollectionResourceItem; short itemid; int cType = 0; unsigned int ucCount = 0; sscanf(buffer, "%d %d %d %d", &newrewarditem->m_Index, &cType, &itemid, &ucCount ); newrewarditem->Set_m_sID( itemid ); newrewarditem->Set_m_cType(cType); newrewarditem->Set_m_ucCount(ucCount); newrewarditem->Set_m_cSecond( _XGameItem::GetItemSecond( newrewarditem->Get_m_cType(), newrewarditem->Get_m_sID()) ); newrewardset->m_listRewardItem.push_back(newrewarditem); currentrewarditemcount++; if( currentrewarditemcount == rewarditemcount ) // 보상이이템의 갯수가 차면 하나의 보상 세트가 완성된다. { currentrewarditemcount = 0; rewarditemcount = 0; currentrewardsetcount++; if( currentrewardsetcount == rewardsetcount ) // 보상세트의 갯수가 차면 하나의 수집 리스트 아이템이 끝난다. { newcollection->m_listRewardSet.push_back(newrewardset); m_listCollectionItem.push_back( newcollection ); collectionlistlinecount = 1; bNewitem = FALSE; } else // 보상 세트의 갯수가 남았으면 다시 보상 아이템의 갯수를 읽어야 한다. { newcollection->m_listRewardSet.push_back(newrewardset); collectionlistlinecount = 11; } } } } if(index == totalcount) { break; } } } while(!feof(fileptr)); #ifdef _XTS_COLLECTION_PACKAGE_071023_KUKURI TCHAR tempstr[256]; memset(tempstr, 0, sizeof(tempstr)); int param1 = 0; int packagecount = 0; _s_Collection_Package* pPackage = NULL; do { if(feof(fileptr)) break; memset(buffer, 0, sizeof(buffer)); if(!fgets(buffer, 511, fileptr)) break; if(strncmp(buffer, _T("_XM_EOS"), 7) == 0) break; if((strlen(buffer) > 0) && buffer[0] != _T(';') && buffer[0] != _T('\n') && buffer[0] != _T('\r')) { sscanf(buffer, "%s %d", tempstr, ¶m1); if(strncmp(tempstr, "_XNPC_INDEX", strlen("_XNPC_INDEX")) == 0) { pPackage = new _s_Collection_Package; pPackage->nNPCId = param1; packagecount = 0; } else if(strncmp(tempstr, "_XPACKAGE_COUNT", strlen("XPACKAGE_COUNT")) == 0) { if(pPackage) { pPackage->nCount = param1; } } else { sscanf(buffer, "%d", ¶m1); packagecount++; // package id if(pPackage) { pPackage->vCollectionId.push_back(param1); } } if(pPackage) { if(packagecount == pPackage->nCount && packagecount != 0) { m_mapCollectionPackage[pPackage->nNPCId] = pPackage; } } } }while(!feof(fileptr)); #endif return TRUE; }