Changeset 925 for trunk/src/@xmltree/private/xml_findstr.c
- Timestamp:
- Feb 17, 2016, 12:52:48 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/@xmltree/private/xml_findstr.c
r820 r925 2 2 3 3 /* 4 Differences with matlab built-in findstr: 4 * $Id: xml_findstr.c 6480 2015-06-13 01:08:30Z guillaume $ 5 * Guillaume Flandin <guillaume@artefact.tk> 6 */ 7 8 /* 9 Differences with built-in findstr: 5 10 - allows to search only the n first occurences of a pattern 6 11 - allows to search only in a substring (given an index of the beginning) 7 12 8 M atlabhack:13 MATLAB hack: 9 14 - doesn't use mxGetString to prevent a copy of the string. 10 - assumes M atlabstores strings as unsigned short (Unicode 16 bits)15 - assumes MATLAB stores strings as unsigned short (Unicode 16 bits) 11 16 matrix.h: typedef uint16_T mxChar; 12 (that's the case for M atlab 5.* and 6.* but Matlab 4.* stores strings13 as double)17 (that's the case for MATLAB 5.*, 6.* and 7.* but MATLAB 4.* stores 18 strings as double and GNU Octave as char, see src/mxarray.h) 14 19 */ 15 20 16 21 /* Comment the following line to use standard mxGetString (slower) */ 22 #if !defined (HAVE_OCTAVE) 17 23 #define __HACK_MXCHAR__ 24 #endif 18 25 19 26 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { … … 28 35 mxArray *out = NULL; 29 36 30 37 /* Check for proper number of arguments. */ 31 38 if ((nrhs == 0) || (nrhs == 1)) 32 39 mexErrMsgTxt("Not enough input arguments."); 33 40 else if (nrhs > 4) 34 41 mexErrMsgTxt("Too many input arguments."); 35 42 else if (nlhs > 1) 36 43 mexErrMsgTxt("Too many output arguments."); 37 44 38 45 /* The input TEXT must be a string */ 39 40 41 46 if (!mxIsChar(prhs[0])) 47 mexErrMsgTxt("Inputs must be character arrays."); 48 stext = mxGetM(prhs[0]) * mxGetN(prhs[0]); 42 49 #ifdef __HACK_MXCHAR__ 43 50 text = mxGetData(prhs[0]); 44 51 #else 45 52 text = mxCalloc(stext+1, sizeof(char)); … … 48 55 49 56 /* The input PATTERN must be a string */ 50 51 57 if (!mxIsChar(prhs[1])) 58 mexErrMsgTxt("Inputs must be character arrays."); 52 59 spattern = mxGetM(prhs[1]) * mxGetN(prhs[1]); 53 60 #ifdef __HACK_MXCHAR__ 54 61 pattern = mxGetData(prhs[1]); 55 62 #else 56 63 pattern = mxCalloc(spattern+1, sizeof(char)); 57 64 mxGetString(prhs[1], pattern, spattern+1); 58 65 #endif 59 66 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 67 /* The input INDEX must be an integer */ 68 if (nrhs > 2) { 69 if ((!mxIsNumeric(prhs[2]) || (mxGetM(prhs[2]) * mxGetN(prhs[2]) != 1))) 70 mexErrMsgTxt("Index input must be an integer."); 71 ind = (unsigned int)mxGetScalar(prhs[2]); 72 if (ind < 1) 73 mexErrMsgTxt("Index must be greater than 1."); 74 } 75 76 /* The input OCCUR must be an integer */ 77 if (nrhs == 4) { 78 if ((!mxIsNumeric(prhs[3]) || (mxGetM(prhs[3]) * mxGetN(prhs[3]) != 1))) 79 mexErrMsgTxt("Index input must be an integer."); 80 nboccur = (unsigned int)mxGetScalar(prhs[3]); 81 } 82 83 /* Find pattern in text */ 77 84 for (i=ind-1;i<stext;i++) { 78 85 for (j=0;j<spattern && i+j<stext;j++) {
Note: See TracChangeset
for help on using the changeset viewer.