Ejemplo n.º 1
0
        /// <summary>
        /// Replaces a value of a CEF string to a new value.
        /// </summary>
        /// <param name="str">The pointer to a CEF string.</param>
        /// <param name="value">The string to replace.</param>
        /// <remarks>This method frees memory allocated for the old string.</remarks>
        public static void Replace(cef_string_t *str, string value)
        {
            if (str == null)
            {
                throw new ArgumentNullException(nameof(str));
            }

            unchecked
            {
                cef_string_utf16_t *s = (cef_string_utf16_t *)str;
                if (s->str != default && s->dtor != default)
                {
                    s->Dtor(s->str);
                }
                if (value == null)
                {
                    s->str    = null;
                    s->length = default;
                    s->dtor   = null;
                }
                else
                {
                    s->str    = (char *)Marshal.StringToHGlobalUni(value);
                    s->length = unchecked ((UIntPtr)value.Length);
                    s->dtor   = CefString.DestructorAddress;
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Allocates a managed <see cref="string"/> and copies a CEF string into it.
 /// </summary>
 /// <param name="str">The pointer to the CEF string.</param>
 /// <returns>A managed string that holds a copy of the CEF string.</returns>
 public static string Read(cef_string_t *str)
 {
     unchecked
     {
         cef_string_utf16_t *s = (cef_string_utf16_t *)str;
         if (s == default || s->str == default)
         {
             return(null);
         }
         return(Marshal.PtrToStringUni((IntPtr)s->str, (int)s->length));
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Frees memory allocated for the <see cref="cef_string_t"/>&apos;s value.
        /// </summary>
        /// <param name="str">The pointer to the CEF string.</param>
        public static void Free(cef_string_t *str)
        {
            cef_string_utf16_t *s = (cef_string_utf16_t *)str;

            if (s->dtor != null)
            {
                s->Dtor(s->str);
                s->dtor = default;
            }
            s->str    = default;
            s->length = UIntPtr.Zero;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Allocates a managed <see cref="string"/>, copies <see cref="cef_string_userfree_t"/>&apos;s
        /// value into it and frees memory allocated for the <see cref="cef_string_userfree_t"/>&apos;s
        /// value.
        /// </summary>
        /// <param name="str">The pointer to the CEF string.</param>
        /// <returns>A managed string that holds a copy of the CEF string.</returns>
        public static string ReadAndFree(cef_string_userfree_t str)
        {
            cef_string_utf16_t *s = str.Base.Base;

            if (s == null)
            {
                return(null);
            }
            string rv = Marshal.PtrToStringUni((IntPtr)s->str, (int)s->length);

            CefNativeApi.cef_string_userfree_utf16_free(str.Base);
            return(rv);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Allocates a managed <see cref="string"/>, copies <see cref="cef_string_t"/>&apos;s value
        /// into it and frees memory allocated for the <see cref="cef_string_t"/>&apos;s value.
        /// </summary>
        /// <param name="str">The pointer to the CEF string.</param>
        /// <returns>A managed string that holds a copy of the CEF string.</returns>
        public static string ReadAndFree(cef_string_t *str)
        {
            cef_string_utf16_t *s = (cef_string_utf16_t *)str;

            if (s == null || s->str == null)
            {
                return(null);
            }

            string rv = Marshal.PtrToStringUni((IntPtr)s->str, (int)s->length);

            if (s->dtor != default)
            {
                s->Dtor(s->str);
                s->dtor = default;
            }
            s->str    = default;
            s->length = UIntPtr.Zero;
            return(rv);
        }