Exemple #1
0
        public virtual RetCode RemoveStateDesc(string stateDesc)
        {
            StringBuilder buf;
            RetCode       rc;
            int           p, q;

            if (string.IsNullOrWhiteSpace(stateDesc))
            {
                rc = RetCode.InvalidArg;

                // PrintError

                goto Cleanup;
            }

            rc = RetCode.Success;

            p = StateDesc.IndexOf(stateDesc, StringComparison.OrdinalIgnoreCase);

            if (p != -1)
            {
                buf = new StringBuilder(Constants.BufSize);

                buf.Append(StateDesc);

                q = p + stateDesc.Length;

                if (!Char.IsWhiteSpace(buf[p]))
                {
                    while (q < buf.Length && Char.IsWhiteSpace(buf[q]))
                    {
                        q++;
                    }
                }

                buf.Remove(p, q - p);

                StateDesc = buf.ToString().Trim();
            }

Cleanup:

            return(rc);
        }
Exemple #2
0
        public virtual RetCode AddStateDesc(string stateDesc, bool dupAllowed = false)
        {
            StringBuilder buf;
            RetCode       rc;
            int           p;

            if (string.IsNullOrWhiteSpace(stateDesc))
            {
                rc = RetCode.InvalidArg;

                // PrintError

                goto Cleanup;
            }

            rc = RetCode.Success;

            p = StateDesc.IndexOf(stateDesc, StringComparison.OrdinalIgnoreCase);

            if (dupAllowed || p == -1)
            {
                buf = new StringBuilder(Constants.BufSize);

                buf.AppendFormat
                (
                    "{0}{1}{2}",
                    StateDesc,
                    StateDesc.Length > 0 ? " " : "",
                    stateDesc
                );

                StateDesc = buf.ToString();
            }

Cleanup:

            return(rc);
        }