void add_anchor_point(const pointi& p) // Add point to our list of anchors. Keep the list sorted. { // Add it to end, since we expect new points to be // relatively greater than existing points. s_anchor_points.push_back(p); // Insertion sort -- bubble down into correct spot. for (int i = s_anchor_points.size() - 2; i >= 0; i--) { if (s_anchor_points[i + 1] < s_anchor_points[i]) { tu_swap(&(s_anchor_points[i]), &(s_anchor_points[i + 1])); } else { // Done bubbling down. break; } } }
void string_substring(const fn_call& fn) { const tu_string& this_str = fn.this_value.to_tu_string(); // Pull a slice out of this_string. int start = 0; int utf8_len = this_str.utf8_length(); int end = utf8_len; if (fn.nargs >= 1) { start = fn.arg(0).to_int(); start = iclamp(start, 0, utf8_len); } if (fn.nargs >= 2) { end = fn.arg(1).to_int(); end = iclamp(end, 0, utf8_len); } if (end < start) tu_swap(&start, &end); // dumb, but that's what the docs say assert(end >= start); fn.result->set_tu_string(this_str.utf8_substring(start, end)); }