internal static String ConvertIdToHexString(String stringId) { StringBuilder stb = new StringBuilder(); char[] stringSymbols = stringId.ToCharArray(); foreach (char ch in stringSymbols) { stb.Append(JavaUtil.IntegerToHexString((int)ch).ToUpperInvariant()); } return(stb.ToString()); }
// empty, no checks /// <summary>Checks options before they are set.</summary> /// <remarks> /// Checks options before they are set. /// First it is checked if only defined options are used, /// second the additional /// <see cref="AssertConsistency(int)"/> /// -method is called. /// </remarks> /// <param name="options">the options to check</param> private void AssertOptionsValid(int options) { int invalidOptions = options & ~GetValidOptions(); if (invalidOptions == 0) { AssertConsistency(options); } else { throw new XMPException("The option bit(s) 0x" + JavaUtil.IntegerToHexString(invalidOptions) + " are invalid!" , XMPError.BADOPTIONS); } }
// this method is ugly, and does a lot. but other breakups cause rescanning and stringbuilder generations internal static void Escape(StringBuilder accum, String str, OutputSettings outputSettings, bool inAttribute , bool normaliseWhite, bool stripLeadingWhite) { bool lastWasWhite = false; bool reachedNonWhite = false; Entities.EscapeMode escapeMode = outputSettings.EscapeMode(); System.Text.Encoding encoder = outputSettings.Charset(); Entities.CoreCharset coreCharset = GetCoreCharsetByName(outputSettings.Charset().Name()); IDictionary <char, String> map = escapeMode.GetMap(); int length = str.Length; int codePoint; for (int offset = 0; offset < length; offset += iText.IO.Util.TextUtil.CharCount(codePoint)) { codePoint = str.CodePointAt(offset); if (normaliseWhite) { if (iText.StyledXmlParser.Jsoup.Helper.StringUtil.IsWhitespace(codePoint)) { if ((stripLeadingWhite && !reachedNonWhite) || lastWasWhite) { continue; } accum.Append(' '); lastWasWhite = true; continue; } else { lastWasWhite = false; reachedNonWhite = true; } } // surrogate pairs, split implementation for efficiency on single char common case (saves creating strings, char[]): if (codePoint < iText.IO.Util.TextUtil.CHARACTER_MIN_SUPPLEMENTARY_CODE_POINT) { char c = (char)codePoint; // html specific and required escapes: switch (c) { case '&': { accum.Append("&"); break; } case (char)0xA0: { if (escapeMode != Entities.EscapeMode.xhtml) { accum.Append(" "); } else { accum.Append(" "); } break; } case '<': { // escape when in character data or when in a xml attribue val; not needed in html attr val if (!inAttribute || escapeMode == Entities.EscapeMode.xhtml) { accum.Append("<"); } else { accum.Append(c); } break; } case '>': { if (!inAttribute) { accum.Append(">"); } else { accum.Append(c); } break; } case '"': { if (inAttribute) { accum.Append("""); } else { accum.Append(c); } break; } default: { if (CanEncode(coreCharset, c, encoder)) { accum.Append(c); } else { if (map.ContainsKey(c)) { accum.Append('&').Append(map.Get(c)).Append(';'); } else { accum.Append("&#x").Append(JavaUtil.IntegerToHexString(codePoint)).Append(';'); } } break; } } } else { String c = new String(iText.IO.Util.TextUtil.ToChars(codePoint)); if (encoder.CanEncode(c)) { // uses fallback encoder for simplicity accum.Append(c); } else { accum.Append("&#x").Append(JavaUtil.IntegerToHexString(codePoint)).Append(';'); } } } }
public virtual void Dump(StreamWriter output) { int i; for (i = 258; i < numStrings_; ++i) { output.WriteLine(" strNxt_[" + i + "] = " + strNxt_[i] + " strChr_ " + JavaUtil.IntegerToHexString(strChr_ [i] & 0xFF) + " strLen_ " + JavaUtil.IntegerToHexString(strLen_[i])); } }
/// <returns>Returns the options as hex bitmask.</returns> public override String ToString() { return("0x" + JavaUtil.IntegerToHexString(options)); }
private static String ToHex4(int n) { String s = "0000" + JavaUtil.IntegerToHexString(n); return(s.Substring(s.Length - 4)); }
private static String ToHex(int ch) { String s = "0000" + JavaUtil.IntegerToHexString(ch); return(s.Substring(Math.Min(4, s.Length - 4))); }
/// <summary>Serializes the node value in XML encoding.</summary> /// <remarks> /// Serializes the node value in XML encoding. Its used for tag bodies and /// attributes.<br /> /// <em>Note:</em> The attribute is always limited by quotes, /// thats why <code>&apos;</code> is never serialized.<br /> /// <em>Note:</em> Control chars are written unescaped, but if the user uses others than tab, LF /// and CR the resulting XML will become invalid. /// </remarks> /// <param name="value">a string</param> /// <param name="forAttribute">flag if string is attribute value (need to additional escape quotes)</param> /// <param name="escapeWhitespaces">Decides if LF, CR and TAB are escaped.</param> /// <returns>Returns the value ready for XML output.</returns> public static String EscapeXML(String value, bool forAttribute, bool escapeWhitespaces) { // quick check if character are contained that need special treatment bool needsEscaping = false; for (int i = 0; i < value.Length; i++) { char c = value[i]; if (c == '<' || c == '>' || c == '&' || (escapeWhitespaces && (c == '\t' || c == '\n' || c == '\r')) || (forAttribute && c == '"')) { // XML chars needsEscaping = true; break; } } if (!needsEscaping) { // fast path return(value); } else { // slow path with escaping StringBuilder buffer = new StringBuilder(value.Length * 4 / 3); for (int i = 0; i < value.Length; i++) { char c = value[i]; if (!(escapeWhitespaces && (c == '\t' || c == '\n' || c == '\r'))) { switch (c) { case '<': { // we do what "Canonical XML" expects // AUDIT: ' not serialized as only outer qoutes are used buffer.Append("<"); continue; } case '>': { buffer.Append(">"); continue; } case '&': { buffer.Append("&"); continue; } case '"': { buffer.Append(forAttribute ? """ : "\""); continue; } default: { buffer.Append(c); continue; } } } else { // write control chars escaped, // if there are others than tab, LF and CR the xml will become invalid. buffer.Append("&#x"); buffer.Append(JavaUtil.IntegerToHexString(c).ToUpperInvariant()); buffer.Append(';'); } } return(buffer.ToString()); } }
private static String ConvertColorFloatToHex(float colorFloat) { String result = "0" + JavaUtil.IntegerToHexString(((int)(colorFloat * 255 + 0.5))).ToUpperInvariant(); return(result.Substring(result.Length - 2)); }