ErrorCode BufferProcessor::readDelimeter(char *output, unsigned int outputSize, unsigned int *outputLen, char delimeter) { while(1) { if (isTerminated()) return ErrorCode::TERMINATED; if (findCharacter(mReadBuffer, mReadBufferLen, outputLen, 0x0A)) { // There is newline in the ReadBuffer, // we will copy the part till newline to line buffer // and then shift the remaining buffer (*outputLen)++; return extractBuffer(output, outputSize, *outputLen); } else { if (bufferFull()) { // line is too long return ErrorCode::SEGMENT_TOO_LONG; } ErrorCode rval = fillBuffer(); assert(rval != ErrorCode::FAILURE); if (rval != ErrorCode::SUCCESS) return rval; continue; } } }
bool BasicEditboxView::mouseDrag(int x, int y) { int textheight = text_height(textfont); if(model->getSelection().isSelecting()) { pair<int, int> oldsel = model->getSelection().getSelection(); CharPos cp = findCharacter(x,y); model->getCursor().updateCursor(cp.totalIndex); model->getSelection().adjustSelection(model->getCursor()); if(y < area_ystart) { view_y = zc_max(0, view_y-1); } if(y > area_ystart+area_height) { int ymost = zc_max(area_height, (int)model->getLines().size()*textheight); view_y = zc_min(ymost-area_height, view_y+1); } if(x < area_xstart) view_x = zc_max(0, view_x-1); if(x > area_xstart+area_width) { int xmost = zc_max(area_width, view_width); view_x = zc_min(xmost-area_width, view_x+1); } if(oldsel != model->getSelection().getSelection()) { return true; } } return false; }
bool BasicEditboxView::mouseClick(int x, int y) { //set the cursor CharPos cp = findCharacter(x,y); model->getCursor().updateCursor(cp.totalIndex); model->getCursor().setPreferredX(); model->getSelection().restartSelection(model->getCursor()); return true; }
void MWState::CharacterManager::deleteSlot(const MWState::Character *character, const MWState::Slot *slot) { std::list<Character>::iterator it = findCharacter(character); it->deleteSlot(slot); if (character->begin() == character->end()) { // All slots deleted, cleanup and remove this character it->cleanup(); if (character == mCurrent) mCurrent = NULL; mCharacters.erase(it); } }
void MWState::CharacterManager::setCurrentCharacter (const Character *character) { std::list<Character>::iterator it = findCharacter(character); mCurrent = &*it; }
void daeURI::internalSetURI(daeString _URIString) { daeChar* tmp; // Store the originalURI so you can fix it post Reset daeString oURI = originalURIString; originalURIString = empty; // Reset everything reset(); // Fix original URI String originalURIString = oURI; uriString = safeCreate(_URIString); tmp = (daeChar*)daeMemorySystem::malloc("tmp",strlen(_URIString)+1); if ((uriString == empty)||(tmp == NULL)) return; strcpy(tmp,uriString); daeChar* curSrc = tmp; #if 1 // Check for a scheme, two or more characters followed by a : // daeChar* colon = (daeChar*)findCharacter(curSrc,':'); daeChar* colon = validScheme(curSrc); // if(colon && (colon-tmp >= 2 )) if(colon) { // Found a scheme, remember it (protocol should be named scheme) *colon = '\0'; protocol = safeCreate(curSrc); // Advance the current pointer past the colon curSrc = colon+1; } // Check for a net path containing an authority, this would begin with // if(curSrc[0] == '/' && curSrc[1] == '/') { // Advance past the double slash to where the authority would start, then find the next slash curSrc = curSrc + 2; daeChar* slash = (daeChar*)findCharacter(curSrc,'/'); // Temporarily remove that slash (avoids some branches) if ( slash != NULL ) { *slash = '\0'; } // Save the text between the slashes as the authority authority = safeCreate(curSrc); // Put the slash back and advance the current pointer to it, this puts us at the start of the path if (slash != NULL ) { *slash = '/'; curSrc = slash; } } // Search backwards from the end of the URI for the # which denotes the fragment (called ID here) daeChar* idSymbol = (daeChar*)findCharacterReverse(curSrc,'#'); if (idSymbol != NULL) { // There was a fragment, isolate it by changing the # to a null *idSymbol = '\0'; idSymbol++; } id = safeCreate(idSymbol); // Search backwards for the last / in the path, everything after is the filename daeChar* fname = (daeChar*)findCharacterReverse(curSrc,'/'); daeChar* dir; if (fname == NULL) { // No / found, so the whole thing is the file name and there is no path fname = curSrc; dir = NULL; } else { // Found a slash, so the filename starts after it and dir starts at curSrc fname++; dir = curSrc; } file = safeCreate(fname); // Pull the extension (if any) off of the filepath daeString extStr = findCharacterReverse(fname,'.'); if (extStr != NULL) extension = safeCreate(extStr+1); // Now pull off the directory path if it exists by putting a zero at the beginning of fname, this insures filepath will end in a slash if(fname != NULL) *fname = 0; filepath = safeCreate(dir); state = uri_loaded; daeMemorySystem::free("tmp",tmp); #else daeBool isAbsolute; daeChar* colon = (daeChar*)findCharacter(curSrc,':'); // IS ABSOLUTE REFERENCE if (colon && (strlen(colon) > 2) && (colon[1] == '/') && (colon[2] == '/')) { *colon = '\0'; protocol = safeCreate(curSrc); curSrc = colon+3; daeString hosttmp = curSrc; daeChar* slash = (daeChar*)findCharacter(curSrc,'/'); if (slash != NULL) { *slash = '\0'; authority = safeCreate(hosttmp); curSrc = slash+1; } isAbsolute = true; } else { protocol = empty; isAbsolute = false; } // Look for the # which denotes the fragment (called ID here) daeChar* idSymbol = (daeChar*)findCharacterReverse(curSrc,'#'); if (idSymbol != NULL) { // There was a fragment, isolate it by changing the # to a null *idSymbol = '\0'; idSymbol++; } daeChar* dir = NULL; daeChar* fname = (daeChar*)findCharacterReverse(curSrc,'/'); if (fname == NULL) fname = curSrc; else { *fname = '\0'; fname++; dir = curSrc; } filepath = safeCreate(dir); int dirLen = (int)strlen(filepath); // append a '/' if ((filepath != empty) && (dirLen > 0) && (filepath[dirLen-1] != '/')) { daeMemorySystem::free("uri",(void*)filepath); filepath = (daeString)daeMemorySystem::malloc("uri", dirLen+2); strcpy((daeChar*)filepath,dir); *((daeChar*)filepath+dirLen) = '/'; *((daeChar*)filepath+dirLen+1) = '\0'; } file = safeCreate(fname); id = safeCreate(idSymbol); daeString extStr = findCharacterReverse(fname,'.'); if (extStr != NULL) extension = safeCreate(extStr+1); state = uri_loaded; daeMemorySystem::free("tmp",tmp); #endif }