int ME_GetCharBack(const ME_String *s, int nPos) { int nVPos = ME_StrVLen(s); assert(nPos < ME_StrLen(s)); if (nPos) nVPos = ME_StrRelPos2(s, nVPos, -nPos); if (nVPos < s->nLen) return s->szData[nVPos]; return -1; }
void ME_StrDeleteV(ME_String *s, int nVChar, int nChars) { int end_ofs; assert(nVChar >=0 && nVChar <= s->nLen); assert(nChars >= 0); assert(nVChar+nChars <= s->nLen); end_ofs = ME_StrRelPos2(s, nVChar, nChars); assert(end_ofs <= s->nLen); memmove(s->szData+nVChar, s->szData+end_ofs, 2*(s->nLen+1-end_ofs)); s->nLen -= (end_ofs - nVChar); }
static BOOL ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *pCursor, int nRelOfs) { ME_DisplayItem *pRun = pCursor->pRun; if (nRelOfs == -1) { if (!pCursor->nOffset) { do { pRun = ME_FindItemBack(pRun, diRunOrParagraph); assert(pRun); switch (pRun->type) { case diRun: break; case diParagraph: if (pRun->member.para.prev_para->type == diTextStart) return FALSE; pRun = ME_FindItemBack(pRun, diRunOrParagraph); /* every paragraph ought to have at least one run */ assert(pRun && pRun->type == diRun); assert(pRun->member.run.nFlags & MERF_ENDPARA); break; default: assert(pRun->type != diRun && pRun->type != diParagraph); return FALSE; } } while (RUN_IS_HIDDEN(&pRun->member.run) || pRun->member.run.nFlags & MERF_HIDDEN); pCursor->pRun = pRun; if (pRun->member.run.nFlags & MERF_ENDPARA) pCursor->nOffset = 0; else pCursor->nOffset = pRun->member.run.strText->nLen; } if (pCursor->nOffset) pCursor->nOffset = ME_StrRelPos2(pCursor->pRun->member.run.strText, pCursor->nOffset, nRelOfs); return TRUE; } else { if (!(pRun->member.run.nFlags & MERF_ENDPARA)) { int new_ofs = ME_StrRelPos2(pRun->member.run.strText, pCursor->nOffset, nRelOfs); if (new_ofs < pRun->member.run.strText->nLen) { pCursor->nOffset = new_ofs; return TRUE; } } do { pRun = ME_FindItemFwd(pRun, diRun); } while (pRun && (RUN_IS_HIDDEN(&pRun->member.run) || pRun->member.run.nFlags & MERF_HIDDEN)); if (pRun) { pCursor->pRun = pRun; pCursor->nOffset = 0; return TRUE; } } return FALSE; }
int ME_PosToVPos(const ME_String *s, int nPos) { if (!nPos) return 0; return ME_StrRelPos2(s, 0, nPos); }