+ * This function is called before doing _anything_ which affects
+ * only part of a line of text. It is used to mark the boundary
+ * between two character positions, and it indicates that some sort
+ * of effect is going to happen on only one side of that boundary.
+ *
+ * The effect of this function is to check whether a CJK
+ * double-width character is straddling the boundary, and to remove
+ * it and replace it with two spaces if so. (Of course, one or
+ * other of those spaces is then likely to be replaced with
+ * something else again, as a result of whatever happens next.)
+ *
+ * Also, if the boundary is at the right-hand _edge_ of the screen,
+ * it implies something deliberate is being done to the rightmost
+ * column position; hence we must clear LATTR_WRAPPED2.
+ *
+ * The input to the function is the coordinates of the _second_
+ * character of the pair.
+ */
+static void check_boundary(Terminal *term, int x, int y)
+{
+ unsigned long *ldata;
+
+ /* Validate input coordinates, just in case. */
+ if (x == 0 || x > term->cols)
+ return;
+
+ ldata = lineptr(y);
+ if (x == term->cols) {
+ ldata[x] &= ~LATTR_WRAPPED2;
+ } else {
+ if ((ldata[x] & (CHAR_MASK | CSET_MASK)) == UCSWIDE) {
+ ldata[x-1] = ldata[x] =
+ (ldata[x-1] &~ (CHAR_MASK | CSET_MASK)) | ATTR_ASCII | ' ';
+ }
+ }
+}
+
+/*