1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-12-20 16:22:38 -05:00

Insure word function that deal with change of character case can work with Unicode characters (capitlize, to upper, to lower).

This commit is contained in:
Renaud 2019-08-03 11:05:16 +08:00
parent 9c1ec4fdf8
commit e4c0f0873a

184
word.c
View File

@ -80,158 +80,122 @@ int wrapword(int f, int n)
return TRUE; return TRUE;
} }
/* /* Move the cursor backward by "n" words. All of the details of motion are
* Move the cursor backward by "n" words. All of the details of motion are
* performed by the "backchar" and "forwchar" routines. Error if you try to * performed by the "backchar" and "forwchar" routines. Error if you try to
* move beyond the buffers. * move beyond the buffers.
*/ */
int backword(int f, int n) int backword( int f, int n) {
{
if( n < 0) if( n < 0)
return forwword( f, -n) ; return forwword( f, -n) ;
if( backchar( FALSE, 1) == FALSE) if( backchar( FALSE, 1) == FALSE)
return FALSE ; return FALSE ;
while( n--) { while( n--) {
while (inword() == FALSE) { while( !inword())
if( backchar( FALSE, 1) == FALSE) if( backchar( FALSE, 1) == FALSE)
return FALSE ; return FALSE ;
}
while (inword() != FALSE) { do {
if( backchar( FALSE, 1) == FALSE) if( backchar( FALSE, 1) == FALSE)
return FALSE ; return FALSE ;
} while( inword()) ;
} }
}
return forwchar( FALSE, 1) ; return forwchar( FALSE, 1) ;
} }
/* /* Move the cursor forward by the specified number of words. All of the motion
* Move the cursor forward by the specified number of words. All of the motion
* is done by "forwchar". Error if you try and move beyond the buffer's end. * is done by "forwchar". Error if you try and move beyond the buffer's end.
*/ */
int forwword(int f, int n) int forwword( int f, int n) {
{
if( n < 0) if( n < 0)
return backword( f, -n) ; return backword( f, -n) ;
while( n--) { while( n--) {
while (inword() == TRUE) { while( inword())
if( forwchar( FALSE, 1) == FALSE) if( forwchar( FALSE, 1) == FALSE)
return FALSE ; return FALSE ;
do {
if( forwchar( FALSE, 1) == FALSE)
return FALSE ;
} while( !inword()) ;
} }
while (inword() == FALSE) {
if (forwchar(FALSE, 1) == FALSE)
return FALSE;
}
}
return TRUE ; return TRUE ;
} }
/* /* Word capitalize, to upper and to lower
* Move the cursor forward by the specified number of words. As you move, */
static boolean uniflip( boolean toupper_f) { /* flip unicode case and forward */
unicode_t c ;
int len ;
len = lgetchar( &c) ; /* len => unicode or extended ASCII */
if( (c <= 255) && ( toupper_f ? islower( c) : isupper( c))) {
c = flipcase( c) ;
ldelchar( 1, FALSE) ;
if( len == 1)
linsert_byte( 1, c) ;
else
linsert( 1, c) ;
lchange( WFHARD) ;
} else
if( forwchar( FALSE, 1) == FALSE)
return FALSE ;
return TRUE ;
}
static boolean capcapword( int n, boolean first_f, boolean rest_f) {
if( curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly() ; /* we are in read only mode */
if( n < 0)
return FALSE ;
while( n--) {
while( !inword())
if( forwchar( FALSE, 1) == FALSE)
return FALSE ;
if( !uniflip( first_f))
return FALSE ;
while( inword())
if( !uniflip( rest_f))
return FALSE ;
}
return TRUE ;
}
/* Move the cursor forward by the specified number of words. As you move,
* convert any characters to upper case. Error if you try and move beyond the * convert any characters to upper case. Error if you try and move beyond the
* end of the buffer. Bound to "M-U". * end of the buffer. Bound to "M-U".
*/ */
int upperword(int f, int n) int upperword( int f, int n) {
{ return capcapword( n, TRUE, TRUE) ;
int c;
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
if (n < 0)
return FALSE;
while (n--) {
while (inword() == FALSE) {
if (forwchar(FALSE, 1) == FALSE)
return FALSE;
}
while (inword() != FALSE) {
c = lgetc(curwp->w_dotp, curwp->w_doto);
if( islower( c)) {
c = flipcase( c) ;
lputc(curwp->w_dotp, curwp->w_doto, c);
lchange(WFHARD);
}
if (forwchar(FALSE, 1) == FALSE)
return FALSE;
}
}
return TRUE;
} }
/*
* Move the cursor forward by the specified number of words. As you move /* Move the cursor forward by the specified number of words. As you move
* convert characters to lower case. Error if you try and move over the end of * convert characters to lower case. Error if you try and move over the end of
* the buffer. Bound to "M-L". * the buffer. Bound to "M-L".
*/ */
int lowerword(int f, int n) int lowerword( int f, int n) {
{ return capcapword( n, FALSE, FALSE) ;
int c;
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
if (n < 0)
return FALSE;
while (n--) {
while (inword() == FALSE) {
if (forwchar(FALSE, 1) == FALSE)
return FALSE;
}
while (inword() != FALSE) {
c = lgetc(curwp->w_dotp, curwp->w_doto);
if( isupper( c)) {
c = flipcase( c) ;
lputc(curwp->w_dotp, curwp->w_doto, c);
lchange(WFHARD);
}
if (forwchar(FALSE, 1) == FALSE)
return FALSE;
}
}
return TRUE;
} }
/* /* Move the cursor forward by the specified number of words. As you move
* Move the cursor forward by the specified number of words. As you move
* convert the first character of the word to upper case, and subsequent * convert the first character of the word to upper case, and subsequent
* characters to lower case. Error if you try and move past the end of the * characters to lower case. Error if you try and move past the end of the
* buffer. Bound to "M-C". * buffer. Bound to "M-C".
*/ */
int capword(int f, int n) int capword( int f, int n) {
{ return capcapword( n, TRUE, FALSE) ;
int c;
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
if (n < 0)
return FALSE;
while (n--) {
while (inword() == FALSE) {
if (forwchar(FALSE, 1) == FALSE)
return FALSE;
}
if (inword() != FALSE) {
c = lgetc(curwp->w_dotp, curwp->w_doto);
if( islower( c)) {
c = flipcase( c) ;
lputc(curwp->w_dotp, curwp->w_doto, c);
lchange(WFHARD);
}
if (forwchar(FALSE, 1) == FALSE)
return FALSE;
while (inword() != FALSE) {
c = lgetc(curwp->w_dotp, curwp->w_doto);
if( isupper( c)) {
c = flipcase( c) ;
lputc(curwp->w_dotp, curwp->w_doto,
c);
lchange(WFHARD);
}
if (forwchar(FALSE, 1) == FALSE)
return FALSE;
}
}
}
return TRUE;
} }
/* /*