1 /* 2 */ 3 4 #include "builtin.ih" 5 b_subString()6void b_subString() 7 { 8 char const *str = string_charp(stack_top()); 9 10 unsigned strLen = strlen(str); 11 12 int firstIdx = int_value(stack_top() - 1); 13 14 if (firstIdx < 0) // use 0 for negative offsets 15 firstIdx = 0; 16 17 int nChars = int_value(stack_top() - 2); 18 19 if (nChars < 0) // use 0 for negative # of chars 20 nChars = 0; 21 22 if (firstIdx >= strLen) // 1st idx points beyond 23 stringcons_charPtr(eb_releaseReg(), ""); // string contents: return 24 // empty string 25 else 26 { 27 stringcons_charPtr(eb_releaseReg(), str + firstIdx); /* intbal copy */ 28 string_reduce(&gb_reg, nChars); /* reduce the strlen if 29 necessary */ 30 } 31 } 32 33 34 35 36