Hello, I didn't know pgsql-sources close,
so I wrote this code just as example of idea.
Can somebody review and make patch for pgsql?
(if this idea is good, of cource).
like-optimization is working only with ASCII, but it is simple to fix.
This programm makes greater string(I tested with KOI8-R):
--
Bye
Juriy Goloveshkin
#include <locale.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
unsigned char table[256];
void create(void){
unsigned char patt[2];
unsigned char dest[2];
int i;
table[0]=0;
patt[1]=0;
for(i=1;i<256;i++){
patt[0]=i;
strxfrm(dest,patt,2);
table[dest[0]]=patt[0];
}
}
char* make_greater_string(const unsigned char *word){
unsigned char *workstr;
int len;
workstr=strdup(word);
while ((len = strlen(workstr)) > 0)
{
unsigned char *lastchar = (unsigned char *) (workstr + len - 1);
unsigned char tmp[2];
while (*lastchar < (unsigned char) 255)
{
strxfrm(tmp,lastchar,2);
*lastchar=(unsigned char)table[tmp[0]+1];
return workstr; /* Success! */
}
*lastchar = '\0';
}
free(workstr);
return NULL;
}
int main(int argc, char *argv[]){
unsigned char *newword;
if (argc<2){
printf("Usage: %s word\n",argv[0]);
return 1;
}
setlocale(LC_ALL,"");
create();
printf("---\n%s\n---\n",&table[20]);
printf("Word is '%s'\n",argv[1]);
newword=make_greater_string(argv[1]);
printf("Bigger word is '%s'\n",newword);
return 0;
}