<commit_before>/** @file
  Main file for endfor and for shell level 1 functions.

  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
  This program and the accompanying materials
  are licensed and made available under the terms and conditions of the BSD License
  which accompanies this distribution.  The full text of the license may be found at
  http://opensource.org/licenses/bsd-license.php

  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

**/

#include "UefiShellLevel1CommandsLib.h"
#include <Library/PrintLib.h>

/**
  Determine if a valid string is a valid number for the 'for' command.

  @param[in] Number The pointer to the string representation of the number to test.

  @retval TRUE    The number is valid.
  @retval FALSE   The number is not valid.
**/
BOOLEAN
EFIAPI
ShellIsValidForNumber (
  IN CONST CHAR16 *Number
  )
{
  if (Number == NULL || *Number == CHAR_NULL) {
    return (FALSE);
  }

  if (*Number == L'-') {
    Number++;
  }

  if (StrLen(Number) == 0) {
    return (FALSE);
  }

  if (StrLen(Number) >= 7) {
    if (StrStr(Number, L" ") != NULL && (StrStr(Number, L" ") - Number) >= 7) {
      return (FALSE);
    }
  }

  if (!ShellIsDecimalDigitCharacter(*Number)) {
    return (FALSE);
  }

  return (TRUE);
}

/**
  Function for 'endfor' command.

  @param[in] ImageHandle  Handle to the Image (NULL if Internal).
  @param[in] SystemTable  Pointer to the System Table (NULL if Internal).<commit_msg>ShellPkg: Update the ‘for’ command to check number length correctly with trailing spaces.<commit_after>/** @file
  Main file for endfor and for shell level 1 functions.

  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
  This program and the accompanying materials
  are licensed and made available under the terms and conditions of the BSD License
  which accompanies this distribution.  The full text of the license may be found at
  http://opensource.org/licenses/bsd-license.php

  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

**/

#include "UefiShellLevel1CommandsLib.h"
#include <Library/PrintLib.h>

/**
  Determine if a valid string is a valid number for the 'for' command.

  @param[in] Number The pointer to the string representation of the number to test.

  @retval TRUE    The number is valid.
  @retval FALSE   The number is not valid.
**/
BOOLEAN
EFIAPI
ShellIsValidForNumber (
  IN CONST CHAR16 *Number
  )
{
  if (Number == NULL || *Number == CHAR_NULL) {
    return (FALSE);
  }

  if (*Number == L'-') {
    Number++;
  }

  if (StrLen(Number) == 0) {
    return (FALSE);
  }

  if (StrLen(Number) >= 7) {
    if ((StrStr(Number, L" ") == NULL) || (((StrStr(Number, L" ") != NULL) && (StrStr(Number, L" ") - Number) >= 7))) {
      return (FALSE);
    }
  }

  if (!ShellIsDecimalDigitCharacter(*Number)) {
    return (FALSE);
  }

  return (TRUE);
}

/**
  Function for 'endfor' command.

  @param[in] ImageHandle  Handle to the Image (NULL if Internal).
  @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
{'fraction_non_alphanumeric': 0.11018518518518519, 'fraction_numerical': 0.009259259259259259, 'mean_word_length': 3.4035326086956523, 'pattern_counts': {'":': 0, '<': 7, '<?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': '522709', 'n_tokens_mistral': 1044, 'n_tokens_neox': 987, 'n_words': 390}