ReactOS  0.4.14-dev-317-g96040ec
string.c File Reference
#include "editor.h"
Include dependency graph for string.c:

Go to the source code of this file.

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (richedit)
 
static int ME_GetOptimalBuffer (int nLen)
 
static ME_Stringmake_string (void(*free)(ME_String *))
 
ME_StringME_MakeStringConst (const WCHAR *str, int len)
 
static void heap_string_free (ME_String *s)
 
ME_StringME_MakeStringEmpty (int nMaxChars)
 
ME_StringME_MakeStringN (LPCWSTR szText, int nMaxChars)
 
ME_StringME_MakeStringR (WCHAR cRepeat, int nMaxChars)
 
void ME_DestroyString (ME_String *s)
 
BOOL ME_InsertString (ME_String *s, int ofs, const WCHAR *insert, int len)
 
BOOL ME_AppendString (ME_String *s, const WCHAR *append, int len)
 
ME_StringME_VSplitString (ME_String *orig, int charidx)
 
void ME_StrDeleteV (ME_String *s, int nVChar, int nChars)
 
static int ME_WordBreakProc (LPWSTR s, INT start, INT len, INT code)
 
int ME_CallWordBreakProc (ME_TextEditor *editor, WCHAR *str, INT len, INT start, INT code)
 
LPWSTR ME_ToUnicode (LONG codepage, LPVOID psz, INT *len)
 
void ME_EndToUnicode (LONG codepage, LPVOID psz)
 

Function Documentation

◆ heap_string_free()

static void heap_string_free ( ME_String s)
static

Definition at line 52 of file string.c.

53 {
54  heap_free( s->szData );
55 }
GLdouble s
Definition: gl.h:2039
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by ME_MakeStringEmpty().

◆ make_string()

static ME_String* make_string ( void(*)(ME_String *)  free)
static

Definition at line 30 of file string.c.

31 {
32  ME_String *s = heap_alloc( sizeof(*s) );
33 
34  if (s) s->free = free;
35  return s;
36 }
#define free
Definition: debug_ros.c:5
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
GLdouble s
Definition: gl.h:2039

Referenced by ME_MakeStringConst(), and ME_MakeStringEmpty().

◆ ME_AppendString()

BOOL ME_AppendString ( ME_String s,
const WCHAR append,
int  len 
)

Definition at line 126 of file string.c.

127 {
128  return ME_InsertString( s, s->nLen, append, len );
129 }
static void append(struct dump_context *dc, const void *data, unsigned size)
Definition: minidump.c:380
BOOL ME_InsertString(ME_String *s, int ofs, const WCHAR *insert, int len)
Definition: string.c:103
GLenum GLsizei len
Definition: glext.h:6722
GLdouble s
Definition: gl.h:2039

Referenced by ME_JoinParagraphs(), and ME_SplitParagraph().

◆ ME_CallWordBreakProc()

int ME_CallWordBreakProc ( ME_TextEditor editor,
WCHAR str,
INT  len,
INT  start,
INT  code 
)

Definition at line 192 of file string.c.

193 {
194  if (!editor->pfnWordBreak) {
195  return ME_WordBreakProc(str, start, len, code);
196  } else if (!editor->bEmulateVersion10) {
197  /* MSDN lied about the third parameter for EditWordBreakProc being the number
198  * of characters, it is actually the number of bytes of the string. */
199  return editor->pfnWordBreak(str, start, len * sizeof(WCHAR), code);
200  } else {
201  int result;
203  NULL, 0, NULL, NULL);
204  char *buffer = heap_alloc(buffer_size);
205  if (!buffer) return 0;
209  heap_free(buffer);
210  return result;
211  }
212 }
#define WideCharToMultiByte
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:99
GLuint buffer
Definition: glext.h:5915
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
static int ME_WordBreakProc(LPWSTR s, INT start, INT len, INT code)
Definition: string.c:162
static void buffer_size(GLcontext *ctx, GLuint *width, GLuint *height)
Definition: swimpl.c:927
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLenum GLsizei len
Definition: glext.h:6722
BOOL bEmulateVersion10
Definition: editstr.h:389
GLuint start
Definition: gl.h:1545
GLuint64EXT * result
Definition: glext.h:11304
EDITWORDBREAKPROCW pfnWordBreak
Definition: editstr.h:421
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by ME_MoveCursorWords().

◆ ME_DestroyString()

void ME_DestroyString ( ME_String s)

Definition at line 96 of file string.c.

97 {
98  if (!s) return;
99  if (s->free) s->free( s );
100  heap_free( s );
101 }
GLdouble s
Definition: gl.h:2039
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by destroy_para(), destroy_undo_item(), draw_text(), ME_CharFromPointContext(), ME_GetRunSizeCommon(), ME_PointFromCharContext(), and para_num_clear().

◆ ME_EndToUnicode()

void ME_EndToUnicode ( LONG  codepage,
LPVOID  psz 
)

Definition at line 236 of file string.c.

237 {
238  if (codepage != CP_UNICODE)
239  heap_free( psz );
240 }
int codepage
Definition: win_iconv.c:156
#define CP_UNICODE
Definition: stg_prop.c:74
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by ME_HandleMessage(), and ME_SetText().

◆ ME_GetOptimalBuffer()

static int ME_GetOptimalBuffer ( int  nLen)
static

Definition at line 25 of file string.c.

26 {
27  return ((sizeof(WCHAR) * nLen) + 128) & ~63;
28 }
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by ME_InsertString(), and ME_MakeStringEmpty().

◆ ME_InsertString()

BOOL ME_InsertString ( ME_String s,
int  ofs,
const WCHAR insert,
int  len 
)

Definition at line 103 of file string.c.

104 {
105  DWORD new_len = s->nLen + len + 1;
106  WCHAR *new;
107 
108  assert( s->nBuffer ); /* Not a const string */
109  assert( ofs <= s->nLen );
110 
111  if( new_len > s->nBuffer )
112  {
113  s->nBuffer = ME_GetOptimalBuffer( new_len );
114  new = heap_realloc( s->szData, s->nBuffer * sizeof(WCHAR) );
115  if (!new) return FALSE;
116  s->szData = new;
117  }
118 
119  memmove( s->szData + ofs + len, s->szData + ofs, (s->nLen - ofs + 1) * sizeof(WCHAR) );
120  memcpy( s->szData + ofs, insert, len * sizeof(WCHAR) );
121  s->nLen += len;
122 
123  return TRUE;
124 }
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
#define TRUE
Definition: types.h:120
static int ME_GetOptimalBuffer(int nLen)
Definition: string.c:25
#define assert(x)
Definition: debug.h:53
static int insert
Definition: xmllint.c:144
static void * heap_realloc(void *mem, size_t len)
Definition: appwiz.h:70
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
static size_t len
Definition: string.c:60
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
GLdouble s
Definition: gl.h:2039

Referenced by ME_AppendString(), and ME_InsertRunAtCursor().

◆ ME_MakeStringConst()

ME_String* ME_MakeStringConst ( const WCHAR str,
int  len 
)

Definition at line 41 of file string.c.

42 {
44  if (!s) return NULL;
45 
46  s->szData = (WCHAR *)str;
47  s->nLen = len;
48  s->nBuffer = 0;
49  return s;
50 }
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
static size_t len
Definition: string.c:60
GLdouble s
Definition: gl.h:2039
static ME_String * make_string(void(*free)(ME_String *))
Definition: string.c:30

Referenced by para_num_init().

◆ ME_MakeStringEmpty()

ME_String* ME_MakeStringEmpty ( int  nMaxChars)

Definition at line 58 of file string.c.

59 {
61 
62  if (!s) return NULL;
63  s->nLen = nMaxChars;
64  s->nBuffer = ME_GetOptimalBuffer(s->nLen + 1);
65  s->szData = heap_alloc( s->nBuffer * sizeof(WCHAR) );
66  if (!s->szData)
67  {
68  heap_free( s );
69  return NULL;
70  }
71  s->szData[s->nLen] = 0;
72  return s;
73 }
static void heap_string_free(ME_String *s)
Definition: string.c:52
static int ME_GetOptimalBuffer(int nLen)
Definition: string.c:25
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLdouble s
Definition: gl.h:2039
static ME_String * make_string(void(*free)(ME_String *))
Definition: string.c:30
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by ME_MakeStringN(), ME_MakeStringR(), and para_num_get_str().

◆ ME_MakeStringN()

ME_String* ME_MakeStringN ( LPCWSTR  szText,
int  nMaxChars 
)

Definition at line 75 of file string.c.

76 {
77  ME_String *s = ME_MakeStringEmpty(nMaxChars);
78 
79  if (!s) return NULL;
80  memcpy(s->szData, szText, s->nLen * sizeof(WCHAR));
81  return s;
82 }
static const WCHAR szText[]
Definition: dialog.c:139
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
ME_String * ME_MakeStringEmpty(int nMaxChars)
Definition: string.c:58
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLdouble s
Definition: gl.h:2039

Referenced by ME_MakeFirstParagraph(), and ME_VSplitString().

◆ ME_MakeStringR()

ME_String* ME_MakeStringR ( WCHAR  cRepeat,
int  nMaxChars 
)

Definition at line 85 of file string.c.

86 {
87  int i;
88  ME_String *s = ME_MakeStringEmpty(nMaxChars);
89 
90  if (!s) return NULL;
91  for (i = 0; i < nMaxChars; i++)
92  s->szData[i] = cRepeat;
93  return s;
94 }
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
ME_String * ME_MakeStringEmpty(int nMaxChars)
Definition: string.c:58
GLdouble s
Definition: gl.h:2039

Referenced by draw_text(), ME_CharFromPointContext(), ME_GetRunSizeCommon(), and ME_PointFromCharContext().

◆ ME_StrDeleteV()

void ME_StrDeleteV ( ME_String s,
int  nVChar,
int  nChars 
)

Definition at line 147 of file string.c.

148 {
149  int end_ofs = nVChar + nChars;
150 
151  assert(s->nBuffer); /* Not a const string */
152  assert(nChars >= 0);
153  assert(nVChar >= 0);
154  assert(end_ofs <= s->nLen);
155 
156  memmove(s->szData + nVChar, s->szData + end_ofs,
157  (s->nLen - end_ofs + 1) * sizeof(WCHAR));
158  s->nLen -= nChars;
159 }
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
#define assert(x)
Definition: debug.h:53
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLdouble s
Definition: gl.h:2039

Referenced by ME_InternalDeleteText().

◆ ME_ToUnicode()

LPWSTR ME_ToUnicode ( LONG  codepage,
LPVOID  psz,
INT len 
)

Definition at line 214 of file string.c.

215 {
216  *len = 0;
217  if (!psz) return NULL;
218 
219  if (codepage == CP_UNICODE)
220  {
221  *len = lstrlenW(psz);
222  return psz;
223  }
224  else {
225  WCHAR *tmp;
226  int nChars = MultiByteToWideChar(codepage, 0, psz, -1, NULL, 0);
227 
228  if(!nChars) return NULL;
229 
230  if((tmp = heap_alloc( nChars * sizeof(WCHAR) )) != NULL)
231  *len = MultiByteToWideChar(codepage, 0, psz, -1, tmp, nChars) - 1;
232  return tmp;
233  }
234 }
#define lstrlenW
Definition: compat.h:407
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
int codepage
Definition: win_iconv.c:156
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLenum GLsizei len
Definition: glext.h:6722
#define MultiByteToWideChar
Definition: compat.h:100
#define CP_UNICODE
Definition: stg_prop.c:74

Referenced by ME_HandleMessage(), and ME_SetText().

◆ ME_VSplitString()

ME_String* ME_VSplitString ( ME_String orig,
int  charidx 
)

Definition at line 131 of file string.c.

132 {
133  ME_String *s;
134 
135  assert(orig->nBuffer); /* Not a const string */
136  assert(charidx>=0);
137  assert(charidx<=orig->nLen);
138 
139  s = ME_MakeStringN(orig->szData+charidx, orig->nLen-charidx);
140  if (!s) return NULL;
141 
142  orig->nLen = charidx;
143  orig->szData[charidx] = '\0';
144  return s;
145 }
int nBuffer
Definition: editstr.h:61
WCHAR * szData
Definition: editstr.h:60
ME_String * ME_MakeStringN(LPCWSTR szText, int nMaxChars)
Definition: string.c:75
#define assert(x)
Definition: debug.h:53
smooth NULL
Definition: ftsmooth.c:416
int nLen
Definition: editstr.h:61
GLdouble s
Definition: gl.h:2039

Referenced by ME_JoinParagraphs(), and ME_SplitParagraph().

◆ ME_WordBreakProc()

static int ME_WordBreakProc ( LPWSTR  s,
INT  start,
INT  len,
INT  code 
)
static

Definition at line 162 of file string.c.

163 {
164  /* FIXME: Native also knows about punctuation */
165  TRACE("s==%s, start==%d, len==%d, code==%d\n",
166  debugstr_wn(s, len), start, len, code);
167 
168  switch (code)
169  {
170  case WB_ISDELIMITER:
171  return ME_IsWSpace(s[start]);
172  case WB_LEFT:
173  case WB_MOVEWORDLEFT:
174  while (start && ME_IsWSpace(s[start - 1]))
175  start--;
176  while (start && !ME_IsWSpace(s[start - 1]))
177  start--;
178  return start;
179  case WB_RIGHT:
180  case WB_MOVEWORDRIGHT:
181  while (start < len && !ME_IsWSpace(s[start]))
182  start++;
183  while (start < len && ME_IsWSpace(s[start]))
184  start++;
185  return start;
186  }
187  return 0;
188 }
#define WB_RIGHT
Definition: winuser.h:551
#define WB_ISDELIMITER
Definition: winuser.h:549
#define WB_MOVEWORDLEFT
Definition: richedit.h:1000
#define WB_LEFT
Definition: winuser.h:550
#define TRACE(s)
Definition: solgame.cpp:4
GLenum GLsizei len
Definition: glext.h:6722
GLdouble s
Definition: gl.h:2039
#define debugstr_wn
Definition: kernel32.h:33
static int ME_IsWSpace(WCHAR ch)
Definition: editor.h:103
GLuint start
Definition: gl.h:1545
#define WB_MOVEWORDRIGHT
Definition: richedit.h:1002

Referenced by ME_CallWordBreakProc().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( richedit  )