/// <summary> /// Return the begin and end of the keyword /// </summary> public static Tuple <int, int> getKeywordPos(int pos, string line) { //Debug.WriteLine(string.Format("INFO: getKeyword; pos={0}; line=\"{1}\"", pos, new string(line))); if ((pos < 0) || (pos >= line.Length)) { return(new Tuple <int, int>(pos, pos)); } // find the beginning of the keyword int beginPos = 0; for (int i1 = pos - 1; i1 >= 0; --i1) { char c = line[i1]; if (AsmSourceTools.isSeparatorChar(c) || Char.IsControl(c) || AsmSourceTools.isRemarkChar(c)) { beginPos = i1 + 1; break; } } // find the end of the keyword int endPos = line.Length; for (int i2 = pos; i2 < line.Length; ++i2) { char c = line[i2]; if (AsmSourceTools.isSeparatorChar(c) || Char.IsControl(c) || AsmSourceTools.isRemarkChar(c)) { endPos = i2; break; } } return(new Tuple <int, int>(beginPos, endPos)); }
/// <summary> /// Returns true if the provided line only contains a remark (and no labels or code, it may have white space) /// </summary> /// <param name="line"></param> /// <returns></returns> public static bool isRemarkOnly(string line) { int nChars = line.Length; for (int i = 0; i < nChars; ++i) { char c = line[i]; if (AsmSourceTools.isRemarkChar(c)) { return(true); } else { if (char.IsWhiteSpace(c)) { // OK } else { return(false); } } } // did not find a remark character; this line is not a remark. return(false); }
private static Tuple <bool, int, int> getLabelDefPos_Regular(string line) { int nChars = line.Length; int i = 0; // find the start of the first keyword for (; i < nChars; ++i) { char c = line[i]; if (AsmSourceTools.isRemarkChar(c)) { return(new Tuple <bool, int, int>(false, 0, 0)); } else if (char.IsWhiteSpace(c)) { // do nothing } else { break; } } if (i >= nChars) { return(new Tuple <bool, int, int>(false, 0, 0)); } int beginPos = i; // position i points to the start of the current keyword //AsmDudeToolsStatic.Output("getLabelEndPos: found first char of first keyword "+ line[i]+"."); for (; i < nChars; ++i) { char c = line[i]; if (c.Equals(':')) { if (i == 0) // we found an empty label { return(new Tuple <bool, int, int>(false, 0, 0)); } else { return(new Tuple <bool, int, int>(true, beginPos, i)); } } else if (AsmSourceTools.isRemarkChar(c)) { return(new Tuple <bool, int, int>(false, 0, 0)); } else if (AsmSourceTools.isSeparatorChar(c)) { // found another keyword: labels can only be the first keyword on a line break; } } return(new Tuple <bool, int, int>(false, 0, 0)); }
public static int getRemarkCharPosition(string line) { for (int i = 0; i < line.Length; ++i) { if (AsmSourceTools.isRemarkChar(line[i])) { return(i); } } return(-1); }
public static Tuple <bool, int, int> getRemarkPos(string line) { int nChars = line.Length; for (int i = 0; i < nChars; ++i) { if (AsmSourceTools.isRemarkChar(line[i])) { return(new Tuple <bool, int, int>(true, i, nChars)); } } return(new Tuple <bool, int, int>(false, nChars, nChars)); }
/// <summary> /// Determine whether the provided pos is in a remark in the provided line. /// </summary> /// <param name="triggerPoint"></param> /// <param name="lineStart"></param> /// <returns></returns> public static bool isInRemark(int pos, string line) { // check if the line contains a remark character before the current point int nChars = line.Length; int startPos = (pos >= nChars) ? nChars - 1 : pos; for (int i = startPos; i >= 0; --i) { if (AsmSourceTools.isRemarkChar(line[i])) { return(true); } } return(false); }