Changeset 3377 in MondoRescue for branches/3.2/mondo/src/common/libmondo-string.c
- Timestamp:
- May 6, 2015, 1:10:17 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mondo/src/common/libmondo-string.c
r3290 r3377 69 69 } 70 70 71 72 /** 73 * Pad a string on both sides so it appears centered. 74 * @param in_out The string to be center-padded (modified). 75 * @param width The width of the final result. 76 */ 77 char *mr_center_string(char *in, int width) 78 { 79 char *scratch = NULL; 80 char *out = NULL; 81 int i; /* purpose */ 82 int len; /* purpose */ 83 int mid; /* purpose */ 84 int x; /* purpose */ 85 86 assert(in != NULL); 87 assert(width > 2); 88 89 if (strlen(in) == 0) { 90 return(NULL); 91 } 92 /* skip initial spaces */ 93 mr_asprintf(scratch, "%s", in); 94 mr_strip_spaces(scratch); 95 len = (int)strlen(scratch); 96 mid = width / 2; 97 x = mid - len / 2; 98 for (i = 0; i < x; i++) { 99 mr_strcat(out,' '); 100 } 101 mr_strcat(out, scratch); 102 mr_free(scratch); 103 for (i = x + len ; i < width - 1; i++) { 104 mr_strcat(out,' '); 105 } 106 return(out); 107 } 71 108 72 109 /**
Note:
See TracChangeset
for help on using the changeset viewer.