<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web.Http.Controllers;
using System.Web.Http.Results;

namespace KryptonDotNet
{
    /// <summary>
    ///  Represents a sorted list of items as content and sort info in header value
    ///  : -h krypton-sort
    /// </summary>
    public class SortedResult : ResponseMessageResult
    {
        public IQueryable<object> Items { get; }
        public SortedResult(IQueryable<object> items, HttpActionContext actionContext) 
            : base(new HttpResponseMessage(System.Net.HttpStatusCode.OK))
        {
            var sort = HeaderUtil.ResolveSortHeader(actionContext.Request.Headers);
            if (!string.IsNullOrEmpty(sort))
            {
                var sortby = Regex.Replace(sort, "[-+]", "");
                var sortClause = sort.StartsWith("-") ? $"{sortby} DESC" : sortby;
                items = items.OrderBy(sortClause);
            }
            this.Items = items;
            this.Response.Content = new ObjectContent(Items.GetType(), Items, actionContext.ControllerContext.Configuration.Formatters.JsonFormatter);
        }
    }<commit_msg>added replace to sortclause directly<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web.Http.Controllers;
using System.Web.Http.Results;

namespace KryptonDotNet
{
    /// <summary>
    ///  Represents a sorted list of items as content and sort info in header value
    ///  : -h krypton-sort
    /// </summary>
    public class SortedResult : ResponseMessageResult
    {
        public IQueryable<object> Items { get; }
        public SortedResult(IQueryable<object> items, HttpActionContext actionContext) 
            : base(new HttpResponseMessage(System.Net.HttpStatusCode.OK))
        {
            var sort = HeaderUtil.ResolveSortHeader(actionContext.Request.Headers);
            if (!string.IsNullOrEmpty(sort))
            {
                var sortClause = sort.Replace("+","").Replace("-", " DESC");
                items = items.OrderBy(sortClause);
            }
            this.Items = items;
            this.Response.Content = new ObjectContent(Items.GetType(), Items, actionContext.ControllerContext.Configuration.Formatters.JsonFormatter);
        }
    }
{'fraction_non_alphanumeric': 0.10838206627680312, 'fraction_numerical': 0.0, 'mean_word_length': 2.7569546120058566, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6150649', 'n_tokens_mistral': 699, 'n_tokens_neox': 705, 'n_words': 155}