public async Task <IActionResult> Search([FromQuery(Name = "q"), Required] string text, int limit = 10)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(new BadRequestResult());
            }

            var characters = await CharacterSearchService.FindCharactersAsync(text);

            return(new OkObjectResult
                   (
                       from codePoint in characters.Take(Math.Max(1, Math.Min(100, limit)))
                       select CodePointProvider.GetCodePoint(codePoint)
                   ));
        }
Exemplo n.º 2
0
        public IActionResult Decompose([FromBody] string text)
        {
            if (text == null || text.Length > 1024)
            {
                return(new BadRequestResult());
            }

            var characters = new List <Models.CodePoint>();

            foreach (int codePoint in new PermissiveCodePointEnumerable(text))
            {
                characters.Add(CodePointProvider.GetCodePoint(codePoint));
            }

            return(new OkObjectResult(characters));
        }
Exemplo n.º 3
0
        public IActionResult GetRange([FromHeader(Name = "Range")] string rawRange)
        {
            RangeHeaderValue range;

            if (rawRange != null)
            {
                if (!RangeHeaderValue.TryParse(rawRange, out range))
                {
                    return(new BadRequestResult());
                }
            }
            else
            {
                range = new RangeHeaderValue(0, 256)
                {
                    Unit = "items"
                };
            }

            // Reject multipart range requests for now…
            if (!range.Unit.Equals("items", StringComparison.OrdinalIgnoreCase) || range.Ranges.Count != 1)
            {
                return(new BadRequestResult());
            }

            var firstRange = range.Ranges.First();

            int offset = checked ((int)(firstRange.From ?? 0));
            int count  = firstRange.To != null?
                         Math.Min(256, checked ((int)firstRange.To.GetValueOrDefault()) - offset + 1) :
                             256;

            return(new RangeResult(CodePointProvider.GetCodePoints(offset, count), new ContentRangeHeaderValue(offset, offset + count - 1, 0x110000)
            {
                Unit = "items"
            }));
        }
Exemplo n.º 4
0
 public IActionResult Get(string hexCodePoint)
 => !TryParseCodePoint(hexCodePoint, out int codePoint) ?
 new NotFoundResult() as IActionResult :
 new OkObjectResult(CodePointProvider.GetCodePoint(codePoint));