styleExpandExp = 1;
void setStyleRange(StyleRange newStyle) {	if (newStyle == null) {		styles = new StyleRange[0];		styleExpandExp = 1;		styleCount = 0;		return;	}	if (newStyle.length ==0) return;	if (newStyle.isUnstyled()) {		clearStyle(newStyle);		return;	}		Point pt = getOverlappingStyles(newStyle.start, newStyle.length);	int newStyleEnd = newStyle.start + newStyle.length - 1;		// no styles exist	if (pt == null) {		insertStyle(newStyle, 0);		return;	}		// newStyle does not overlap any other styles	if (pt.y == 0) {		insertMergeStyle(newStyle, pt.x);		return;	} 	// the newStyle overlaps one or more of the existing styles	boolean added = false; // indicates whether or not the new style has been added	int count = 0;	// pt.x is the index of the first overlapped style, pt.y is the number of overlapped	// styles	for (int i=pt.x; count<pt.y; i++) {		StyleRange overlap = styles[i];		int overlapEnd = overlap.start + overlap.length - 1;		if (overlap.start < newStyle.start) {			if (overlapEnd <= newStyleEnd) {				// the end of overlap needs to be replaced by newStyle				if (newStyle.similarTo(overlap)) {					// update overlap to accomodate the new style					overlap.length = newStyle.start + newStyle.length - overlap.start;				} else {					overlap.length=newStyle.start - overlap.start;					// see if newStyle can be merged with the style after overlap, if so,					// processing is done					if (mergeStyleAfter(newStyle, i+1)) break;					// otherwise, insert the newStyle, newStyle may still overlap other					// styles after it so continue processing						insertStyle(newStyle, i+1);					i++;				}				added = true;			} else {				// middle of overlap needs to be replaced by newStyle, this will				// cause overlap to be broken into two				if (newStyle.similarTo(overlap)) break;				StyleRange endStyle = (StyleRange)overlap.clone();				endStyle.start = newStyleEnd + 1;				endStyle.length = overlapEnd - newStyleEnd;				overlap.length = newStyle.start - overlap.start;				insertStyle(newStyle, i+1);				i++;				insertStyle(endStyle, i+1);				// when newStyle overlaps the middle of a style, this implies that				// processing is done (no more overlapped styles)				break;			}		} else {			if (overlapEnd <= newStyleEnd) {					// overlap will be replaced by the newStyle, make sure newStyle				// hasn't already been added, if it has just delete overlap				if (!added) {					styles[i] = newStyle;					added = true;				} else {					deleteStyle(i);					i--;				}			} else {				// beginning of overlap needs to be replaced by newStyle				overlap.start=newStyleEnd + 1;				overlap.length=overlapEnd - overlap.start + 1;				if (!added) {					insertMergeStyle(newStyle, i);				}				// when newStyle overlaps only the beginning of a style, this implies 				// that processing is done (no more overlapped styles)				break;			}		}					count++;	}}