| Ilya Zakharevich on Sat, 1 Mar 2003 02:01:44 -0800 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| [PATCH CVS] Strchr(77), Strchr([79,75]) |
This patch allows one to invert Vecsmall("OK").
Enjoy,
Ilya
P.S. Should not we replace t_STR to allow lgef() - which would specify the
length of the string. This would allow to have strings with
embedded \0 as well... I grepped for t_STR, and think the patch
would be very short.
--- ./src/language/anal.h-pre Sat Feb 22 23:58:44 2003
+++ ./src/language/anal.h Sat Mar 1 01:49:02 2003
@@ -262,6 +262,7 @@ void writetex(const char *s, GEN g);
GEN Str(GEN g);
GEN Strexpand(GEN g);
GEN Strtex(GEN g);
+GEN Str_char(GEN g);
/* for output */
typedef struct {
--- ./src/language/es.c-pre Sat Mar 1 01:48:40 2003
+++ ./src/language/es.c Sat Mar 1 01:48:10 2003
@@ -725,6 +725,33 @@ Strexpand(GEN g) {
GEN z = STRtoGENstr(t);
free(t); free(s); return z;
}
+GEN
+Str_char(GEN g) {
+ long n;
+ unsigned char buf[2];
+
+ if (is_vec_t(typ(g))) {
+ long l = lg(g), i;
+ long len = (l+BYTES_IN_LONG-1) >> TWOPOTBYTES_IN_LONG;
+ GEN x = cgetg(len+1, t_STR);
+ char *s = GSTR(x);
+
+ for (i=1; i<l; i++) {
+ n = itos((GEN)g[i]);
+ if (n <= 0 || n > 255)
+ err(talker, "Out of range in integer -> character conversion");
+ *s++ = n;
+ }
+ *s = 0;
+ return x;
+ }
+ n = itos(g);
+ if (n <= 0 || n > 255)
+ err(talker, "Out of range in integer -> character conversion");
+ buf[0] = n; /* UTF8 ? */
+ buf[1] = 0;
+ return STRtoGENstr(buf);
+}
/********************************************************************/
/** **/
--- ./src/language/helpmsg.c-pre Sun Jan 12 16:32:58 2003
+++ ./src/language/helpmsg.c Sat Mar 1 01:52:54 2003
@@ -27,6 +27,7 @@ char *helpmessages_basic[]={
"Ser(x,{v=x}): convert x (usually a vector) into a power series with variable v, starting with the constant coefficient",
"Set({x=[]}): convert x into a set, i.e. a row vector with strictly increasing coefficients. Empty set if x is omitted",
"Str({str}*): concatenates its (string) argument into a single string",
+ "Strchr(x): converts x to string, translating each integer into a characters",
"Strexpand({str}*): concatenates its (string) argument into a single string, performing tilde expansion",
"Strtex({str}*): translates its (string) arguments to TeX format and returns the resulting string",
"Vec({x=[]}): transforms the object x into a vector. Used mainly if x is a polynomial or a power series. Empty vector if x is omitted",
--- ./src/language/init.c-pre Sat Feb 22 19:58:36 2003
+++ ./src/language/init.c Sat Mar 1 01:50:36 2003
@@ -2018,6 +2018,7 @@ entree functions_basic[]={
{"Ser",14,(void*)gtoser,2,"GDn"},
{"Set",0,(void*)gtoset,2,"DG"},
{"Str",0,(void*)Str,2,"s*"},
+{"Strchr",18,(void*)Str_char,2,"G"},
{"Strexpand",0,(void*)Strexpand,2,"s*"},
{"Strtex",0,(void*)Strtex,2,"s*"},
{"Vec",0,(void*)gtovec,2,"DG"},