Fossil SCM

Moved string_xform.c code into encode.c, since that code serves a similar purpose.

stephan 2008-02-05 20:48 trunk
Commit 91f151d57a6e90b4928793959bcec9e673ce2f22
1 file changed +67
+67
--- src/encode.c
+++ src/encode.c
@@ -469,5 +469,72 @@
469469
while( *z && n-- ){
470470
*z = zEncode[zDecode[(*z)&0x7f]&0x1f];
471471
z++;
472472
}
473473
}
474
+
475
+#if INTERFACE
476
+/**
477
+string_unary_xform_f is a typedef for funcs with the following policy:
478
+
479
+They accept a const string which they then transform into some other
480
+form. They return a transformed copy, which the caller is responsible
481
+for freeing.
482
+
483
+The intention of this is to provide a way for a generic query routine
484
+to format specific column data (e.g. transform an object ID into a
485
+link to that object).
486
+*/
487
+typedef char * (*string_unary_xform_f)( char const * );
488
+
489
+#endif // INTERFACE
490
+
491
+#if 0
492
+/** A no-op transformer which can be used as a placeholder.
493
+
494
+Conforms to the string_unary_xform_f typedef's policies.
495
+*/
496
+char * strxform_copy( char const * uuid )
497
+{
498
+ int len = strlen(uuid) + 1;
499
+ char * ret = (char *) malloc( len );
500
+ ret[len] = '\0';
501
+ strncpy( ret, uuid, len-1 );
502
+ return ret;
503
+}
504
+#endif
505
+
506
+/**
507
+Returns a hyperlink to uuid.
508
+
509
+Conforms to the string_unary_xform_f typedef's policies.
510
+*/
511
+char * strxform_link_to_uuid( char const * uuid )
512
+{
513
+ const int offset = 10;
514
+ char shortname[offset+1];
515
+ shortname[offset] = '\0';
516
+ memcpy( shortname, uuid, offset );
517
+ return mprintf("<tt><a href='%s/vinfo/%s'><span style='font-size:1.5em'>"
518
+ "%s</span>%s</a></tt>",
519
+ g.zBaseURL, uuid, shortname, uuid+offset );
520
+}
521
+
522
+/** Returns a hyperlink to the given tag.
523
+
524
+Conforms to the string_unary_xform_f typedef's policies.
525
+*/
526
+char * strxform_link_to_tagid( char const * tagid )
527
+{
528
+ return mprintf( "<a href='%s/tagview?tagid=%s'>%s</a>",
529
+ g.zBaseURL, tagid, tagid );
530
+}
531
+
532
+/** Returns a hyperlink to the named tag.
533
+
534
+Conforms to the string_unary_xform_f typedef's policies.
535
+*/
536
+char * strxform_link_to_tagname( char const * tagid )
537
+{
538
+ return mprintf( "<a href='%s/tagview/%s'>%s</a>",
539
+ g.zBaseURL, tagid, tagid );
540
+}
474541
--- src/encode.c
+++ src/encode.c
@@ -469,5 +469,72 @@
469 while( *z && n-- ){
470 *z = zEncode[zDecode[(*z)&0x7f]&0x1f];
471 z++;
472 }
473 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
474
--- src/encode.c
+++ src/encode.c
@@ -469,5 +469,72 @@
469 while( *z && n-- ){
470 *z = zEncode[zDecode[(*z)&0x7f]&0x1f];
471 z++;
472 }
473 }
474
475 #if INTERFACE
476 /**
477 string_unary_xform_f is a typedef for funcs with the following policy:
478
479 They accept a const string which they then transform into some other
480 form. They return a transformed copy, which the caller is responsible
481 for freeing.
482
483 The intention of this is to provide a way for a generic query routine
484 to format specific column data (e.g. transform an object ID into a
485 link to that object).
486 */
487 typedef char * (*string_unary_xform_f)( char const * );
488
489 #endif // INTERFACE
490
491 #if 0
492 /** A no-op transformer which can be used as a placeholder.
493
494 Conforms to the string_unary_xform_f typedef's policies.
495 */
496 char * strxform_copy( char const * uuid )
497 {
498 int len = strlen(uuid) + 1;
499 char * ret = (char *) malloc( len );
500 ret[len] = '\0';
501 strncpy( ret, uuid, len-1 );
502 return ret;
503 }
504 #endif
505
506 /**
507 Returns a hyperlink to uuid.
508
509 Conforms to the string_unary_xform_f typedef's policies.
510 */
511 char * strxform_link_to_uuid( char const * uuid )
512 {
513 const int offset = 10;
514 char shortname[offset+1];
515 shortname[offset] = '\0';
516 memcpy( shortname, uuid, offset );
517 return mprintf("<tt><a href='%s/vinfo/%s'><span style='font-size:1.5em'>"
518 "%s</span>%s</a></tt>",
519 g.zBaseURL, uuid, shortname, uuid+offset );
520 }
521
522 /** Returns a hyperlink to the given tag.
523
524 Conforms to the string_unary_xform_f typedef's policies.
525 */
526 char * strxform_link_to_tagid( char const * tagid )
527 {
528 return mprintf( "<a href='%s/tagview?tagid=%s'>%s</a>",
529 g.zBaseURL, tagid, tagid );
530 }
531
532 /** Returns a hyperlink to the named tag.
533
534 Conforms to the string_unary_xform_f typedef's policies.
535 */
536 char * strxform_link_to_tagname( char const * tagid )
537 {
538 return mprintf( "<a href='%s/tagview/%s'>%s</a>",
539 g.zBaseURL, tagid, tagid );
540 }
541

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button