Exemple #1
0
        private static string Convert(string pattern, ref Native.convert_input input)
        {
            fixed(char *pPattern = pattern)
            {
                input.pattern        = pPattern;
                input.pattern_length = (uint)pattern.Length;
                input.options       |= PcreConstants.CONVERT_UTF;

                var errorCode = Native.convert(ref input, out var result);

                try
                {
                    if (errorCode != 0)
                    {
                        throw new ArgumentException($"Could not convert pattern '{pattern}': {Native.GetErrorMessage(errorCode)} at offset {result.output_length}");
                    }

                    return(new string(result.output, 0, (int)result.output_length));
                }
                finally
                {
                    if (result.output != null)
                    {
                        Native.convert_result_free(result.output);
                    }
                }
            }
        }
Exemple #2
0
        private static string BasicConvert(string pattern, uint options)
        {
            if (pattern == null)
            {
                throw new ArgumentNullException(nameof(pattern));
            }

            var input = new Native.convert_input
            {
                options = options
            };

            return(Convert(pattern, ref input));
        }
Exemple #3
0
        public static string FromGlob(string pattern, PcreGlobConversionOptions options)
        {
            if (pattern == null)
            {
                throw new ArgumentNullException(nameof(pattern));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var input = new Native.convert_input();

            options.FillConvertInput(ref input);

            return(Convert(pattern, ref input));
        }
Exemple #4
0
 internal void FillConvertInput(ref Native.convert_input input)
 {
     input.options        = GetConvertOptions();
     input.glob_escape    = EscapeCharacter;
     input.glob_separator = SeparatorCharacter;
 }