예제 #1
0
파일: SmsPdu.cs 프로젝트: xsjames/GSMComm
        /// <summary>
        /// Modifies the message text so that it is safe to be sent via GSM 7-Bit default encoding.
        /// </summary>
        /// <param name="data">The message text.</param>
        /// <param name="charsCorrected">Will be set to true if the message length was corrected.</param>
        /// <param name="lengthCorrected">Will be set to true if one or more characters were replaced.</param>
        /// <returns>The converted message text.</returns>
        /// <remarks>Replaces invalid characters in the text and truncates it to the maximum allowed length.</remarks>
        public static string GetSafeText(string data, out bool lengthCorrected, out bool charsCorrected)
        {
            string str;
            string str1;
            bool   flag = false;

            lengthCorrected = false;
            charsCorrected  = false;
            if (data.Length <= 160)
            {
                str = data;
            }
            else
            {
                str             = data.Substring(0, 160);
                lengthCorrected = true;
            }
            do
            {
                str1 = TextDataConverter.StringTo7Bit(str, false, out flag);
                if (flag)
                {
                    charsCorrected = true;
                }
                if (str1.Length <= 160)
                {
                    continue;
                }
                str             = data.Substring(0, str.Length - 1);
                lengthCorrected = true;
            }while (str1.Length > 160);
            string str2 = TextDataConverter.SevenBitToString(str1);

            return(str2);
        }
예제 #2
0
파일: SmsPdu.cs 프로젝트: xsjames/GSMComm
        /// <summary>
        /// Encodes the specified text as 7-Bit user data in this instance.
        /// </summary>
        /// <param name="text">The text to encode.</param>
        /// <remarks>The text is converted to the GSM 7-Bit default alphabet first, then it is packed into octets.
        /// The final result is saved in the properties <see cref="P:GsmComm.PduConverter.SmsPdu.UserData" /> and <see cref="P:GsmComm.PduConverter.SmsPdu.UserDataLength" />.
        /// </remarks>
        /// <exception cref="T:System.ArgumentException">Text is too long.</exception>
        protected void Encode7BitText(string text)
        {
            string str    = TextDataConverter.StringTo7Bit(text);
            int    length = str.Length;

            if (length <= 160)
            {
                this.SetUserData(TextDataConverter.SeptetsToOctetsInt(str), (byte)length);
                return;
            }
            else
            {
                string[] strArrays = new string[5];
                strArrays[0] = "Text is too long. A maximum of ";
                int num = 160;
                strArrays[1] = num.ToString();
                strArrays[2] = " resulting septets is allowed. The current input results in ";
                strArrays[3] = length.ToString();
                strArrays[4] = " septets.";
                throw new ArgumentException(string.Concat(strArrays));
            }
        }
예제 #3
0
파일: SmsPdu.cs 프로젝트: xsjames/GSMComm
 /// <summary>
 /// Gets the length in septets of the specified text.
 /// </summary>
 /// <param name="text">The text the get the length for.</param>
 /// <returns>The text length.</returns>
 public static int GetTextLength(string text)
 {
     return(TextDataConverter.StringTo7Bit(text).Length);
 }
예제 #4
0
        /// <summary>
        /// Converts a string consisting of characters from the ISO-8859-1
        /// character set into a string of corresponding characters of the
        /// "GSM 7-bit default alphabet" character set.
        /// </summary>
        /// <param name="s">The string to convert.</param>
        /// <returns>The converted string.</returns>
        /// <remarks>
        /// <para>Throws an exception when an invalid character is encountered in the string.</para>
        /// <para>Note that the converted string does not need to have the same
        /// length as the original one because some characters may be escaped.</para>
        /// </remarks>
        /// <exception cref="T:System.ArgumentException">An invalid character is encountered in the string.</exception>
        public static string StringTo7Bit(string s)
        {
            bool flag = false;

            return(TextDataConverter.StringTo7Bit(s, true, out flag));
        }