SgObject Sg_BuildPath(SgString *path, SgString *file) { int psize = SG_STRING_SIZE(path), fsize = SG_STRING_SIZE(file); int i, j, offset = 1; SgObject ret; if (SG_STRING_VALUE_AT(path, psize-1) == '/') offset--; ret = Sg_ReserveString(psize + fsize + offset, 0); for (i = 0; i < psize; i++) { SG_STRING_VALUE_AT(ret, i) = SG_STRING_VALUE_AT(path, i); } if (offset) { SG_STRING_VALUE_AT(ret, i++) = '/'; } for (j = 0; j < fsize; i++, j++) { SG_STRING_VALUE_AT(ret, i) = SG_STRING_VALUE_AT(file, j); } return ret; }
static SgObject remove_backslashes(SgObject path) { int i, j, count = 0; SgObject r; for (i = 0; i < SG_STRING_SIZE(path); i++) { if (SG_STRING_VALUE_AT(path, i) != '\\') count++; } /* no backslash */ if (SG_STRING_SIZE(path) == count) return path; r = Sg_ReserveString(count, '\0'); for (i = 0, j = 0; i < SG_STRING_SIZE(path); i++) { if (SG_STRING_VALUE_AT(path, i) != '\\') { SG_STRING_VALUE_AT(r, j++) = SG_STRING_VALUE_AT(path, i); } } return r; }