Skip to content

Add characters_without_whitespace to the Text Analyzer - #19

Merged
kushagarwal2910-lang merged 1 commit into
github-community-gitam:mainfrom
SakarPaisen:feat/text-analyzer-non-whitespace-10
Oct 22, 2026
Merged

kushagarwal2910-lang merged 1 commit into
github-community-gitam:mainfrom
SakarPaisen:feat/text-analyzer-non-whitespace-10

Conversation

@SakarPaisen

Copy link
Copy Markdown
Contributor

What

Closes #10.

analyze_text now reports characters_without_whitespace alongside the existing characters count. It counts every character for which str.isspace() is false, so punctuation and digits still count and spaces, tabs, newlines and a Unicode non-breaking space do not.

>>> analyze_text("Hi there!\n")
{"characters": 10, "characters_without_whitespace": 8, "words": 2, ...}

Scope

  • src/mcp_tools_lab/tools/text.py — one new field plus a docstring note.
  • tests/test_text.py — updated the exact-result assertion for empty text and added three focused tests.
  • docs/tool-guide.md — documents the new field.
  • No server, dependency or other tool changes. All existing fields keep their current values.

Tests added

  • Documented example: "Hi there!\n" → characters=10, characters_without_whitespace=8.
  • Punctuation and digits still count: "a, 1\tb" → characters=6, characters_without_whitespace=4.
  • Whitespace only: " \t\r\n\u00a0" → characters=5, characters_without_whitespace=0, words=0.

Checks

  • python -m pytest tests/test_text.py -q — 6 passed
  • python -m pytest -q — 65 passed
  • python examples/try_tools.py — runs, shows the new field
  • python .github/scripts/check_rules.py — Scanned 11 files under src/ for print() and network imports: OK

Python: 3.13 on Windows 11.

Note on issue choice: #1 ("Count empty lines") already has a claim comment from another contributor and is not assigned, so per contributions.md ("wait for a maintainer to confirm if the issue is already claimed") I took this separate starter task instead. Happy to hold both until a maintainer confirms.

(Full disclosure: I used an AI coding assistant for this change, and I reviewed and verified everything submitted here.)

analyze_text now reports how many characters are not recognized by str.isspace(), next to the existing characters count. Punctuation and digits still count, and empty or whitespace-only input is zero. Existing fields are unchanged. Tests cover the documented example, spaces/tabs/newlines plus a Unicode non-breaking space, and the updated exact result for empty text; the tool guide documents the field.
@kushagarwal2910-lang
kushagarwal2910-lang merged commit 26cb37d into github-community-gitam:main Oct 22, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Count characters excluding whitespace in Text Analyzer

2 participants